How can I store the result after each iteration in a row vector?

1 vue (au cours des 30 derniers jours)
Sakshi Koundal le 10 Avr 2021
Commenté : Sakshi Koundal le 11 Avr 2021
Below is the sum equation which is of similar form that I need to write in my Objective Function.
I have written the following code using two 'for' loops, it's working fine but the final answer Asum(As) it is storing is only of the last iteration.
Ac = [1 2 3 4];
for i=1:lenght(Ac)
end
end
whereas I need the result in the form of a row vector as shown below:
As = [2 3 3 4 4 5 5 6]
Kindly help, thanks
2 commentairesAfficher AucuneMasquer Aucune
Stephen23 le 11 Avr 2021
Modifié(e) : Stephen23 le 11 Avr 2021
Using two loops is not a very good use of MATLAB.
Ac = [1,2,3,4];
C = 1×8
2 3 3 4 4 5 5 6
Sakshi Koundal le 11 Avr 2021
Thank you Stephen, I'll modify my code.

Connectez-vous pour commenter.

Réponse acceptée

David Fletcher le 10 Avr 2021
A quick hack would be:
Ac = [1 2 3 4];
As=[];
for i=1:length(Ac)
end
end
1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Sakshi Koundal le 11 Avr 2021
Thanks David, I get it.. ^^

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by