Using Matlab write the following code a Use a for loop and f
Using Matlab, write the following code:
a) Use a for loop and fprintf command to print out a column vector of numbers from 1 to 5.
b) Use the disp command to print a column vector
Solution
% matlab code
% for loop and fprintf command to print out a column vector of numbers from 1 to 5.
column_vector = zeros( 5 , 1);
for i=1:5
column_vector(i) = i;
end
disp(\"Using fprintf command: \");
for i=1:5
fprintf(\"%d\ \",column_vector(i));
end
% disp command to print a column vector
disp(\"\ Using disp command: \");
disp(column_vector);
%{
output:
Using fprintf command:
1
2
3
4
5
Using disp command:
1
2
3
4
5
%}
