- Suppose "value" is the scalar result
Indexing in "for loops"
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Charles Ofori
am 9 Feb. 2021
Kommentiert: Charles Ofori
am 9 Feb. 2021
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
0 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 9 Feb. 2021
Bearbeitet: KALYAN ACHARJYA
am 9 Feb. 2021
Here I have considering three assumptions and tried to reproduce the same, there is no error
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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!