Posted By:
20 Mar, 2013 6:39 pm PDT

indexing array in matlab using a for or while loop

I want to write a loop in which the number of iteration or loops is stored in a variable. For example, if the loop is executed 5 times, my variable should have the entries as

[ 1,2,3,4,5]


You have to use positive indexing for matlab, 0 is not allowed. Using for loop:

>>for i = 1:10

A(i) = i;



OR while loop


>>while i <10

i = i+1;

A(i) = i;



Please watch the video and matlab file for details

Attachment: for_while_indexing.m
Was it useful?  

Please login to reply to this problem.