Little Bit Help Required Regarding Loop
Mostra commenti meno recenti
Hi EveryOne
I am currently working on this code
a=[1 2 3]
b=[3 4 5]
c=[34 5 6 ]
for i=1:1:3;
C = {[a];[b];[c]};
d= cellfun(@(v)v(i),C)
end
And the output is
d =
1
3
34
d =
2
4
5
d =
3
5
6
Every time loop runs it updated the last results.
I just want to save all the values means every time when loop run it keep save the last results and save the new results in the new coloumn
When I use
d(i)= cellfun(@(v)v(i),C)
The code give error
In an assignment A(I) = B, the number of elements in B and I must be the same.
Please help in this matter
Thanks
Regards
1 Commento
Note that these square brackets are totally superfluous:
C = {[a];[b];[c]};
All you need is:
C = {a;b;c};
You will notice that these superfluous square brackets are underlined by the MATLAB Editor:
Also there is no need to completely redefine C on every loop iteration: it is simpler and more efficient to just define it once before the loop.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!