Little Bit Help Required Regarding Loop
Afficher commentaires plus anciens
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 commentaire
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!