MATLAB: Indexing in “for loops”

indexinglooping

I already have a code i want to run multiple times because it has some form of randomisation where every run produces a different value. So basically, i want to generate a list of values. I used the for loop in runnning the script. First i declared an empty array then used a loop to run the random number generator about 100 times. Something like this:
group=ones(100,1);
for i=1:100
run('try_2');
group(i,:)=value;
end
It worked at first but upon subsequent trials, it is no longer working. I get an error message " subscript indices must either be real positive integers or logicals loops "
Is there any way i can get by this. I just want to be able to run my script multiple times and generate a vector or matrix that collects the answers at every run. Thanks

Best Answer

Here I have considering three assumptions and tried to reproduce the same, there is no error
  1. Suppose "value" is the scalar result
group=zeros(1,100);
for i=1:100
%run('try_2'); % this command return the value, right?
group(i)=value;
end
2. Value is a vector, let say "value" is 1D array with fixed length n
group=zeros(100,n);
for i=1:100
%run('try_2');
group(i,:)=value;
end
3. Value is varrying result as interation progress, in such case use cell array to store the result
group=cell(1,100);
for i=1:100
%run('try_2');
group{i}=value;
end
Rest is OK, just ensure that respective "run" commnad generete the value variable. Still unsolved please provide the detail of try_2 ??
Hope it Helps!