In: Computer Science
Hi I'm trying to use a for loop in Matlab to run over the times inside a vector. For example N = [10 20 30], the for loop should run the first number of the loop 10 times once and then the same loop again 20 times and so on. So the program must run the loop 3 times but with the different numbers of the vector.
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
% Take the vector
N = [10 2 1]
% Start a for loop
for i=1:length(N)
% each time loop for N[i] number of times
for j=1:N(i)
% Print the j value
disp(j)
end
disp(' ')
end
================