1) The primary form of data in MATLAB is vectors. They can be one-dimensional (i
ID: 3561701 • Letter: 1
Question
1) The primary form of data in MATLAB is vectors. They can be one-dimensional (i.e., vectors), or two-dimensional (i.e., matrices).
a) Write the MATLAB code to create a 1x3 vector containing the elements [1,2,3]. Additionally, write the MATLAB code to create a 3x1 vector with the same elements.
b) Write the MATLAB code to create the vector [2,4,6,...,98,100] and store it in a variable named x(Hint: There is a shorthand notation for regularly spaced vectors).
c) Write the MATLAB code to create a 2x2 matrix containing the elements [1,2,3,4] (The order of the numbers do not matter).
Explanation / Answer
Matlab Code - (a)
clc;clear all;close all;
a=[1,2,3];
b=[1;2;3];
disp('The 1 x 3 vector is');a
disp('The 3 x 1 vector is');b
Matlab Code - (b)
clc;clear all;close all;
x=2:2:100;
disp('The required vector is');x
Matlab Code - (c)
clc;clear all;close all;
k=[1,2;3,4];
disp('The required 2x2 square matrix is:');k
**YOU MAY RUN THESE CODES ON MATLAB. THEY ARE PERFECT !!
**PLEASE RATE WITH 5 STARS !!! THANKS :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.