MATLAB: Use a “while” loop to create the vector x = [4 16 28 40]. Note the constant increment of 12.How can i put the ic values in x.Help please

homeworkwhile loopzeros command

clear all;
disp('#1');
x=zeros(1,4);
format compact
% your code goes here
ic=4
while ic<40
ic=ic+12
end
% display x
fprintf('\nx = [ %d %d %d %d ]\n\n',x)

Best Answer

You need something inside the while loop that sets the value of the x elements. E.g.,
k = 1;
while ic < 40
x(k) = ________; % you fill in this line
k = k + 1;
ic = ic + 12;
end
Also, you should double check that the condition ic < 40 is really the condition you want to use for this assignment.
Related Question