vector that displays [0 5 10 15]

4 vues (au cours des 30 derniers jours)
Mahmoud Chawki
Mahmoud Chawki le 18 Mai 2022
Commenté : Mahmoud Chawki le 18 Mai 2022
i want a for loops that displays the following vector
[0 5 10 15]
  3 commentaires
Mahmoud Chawki
Mahmoud Chawki le 18 Mai 2022
to build the vector
Mahmoud Chawki
Mahmoud Chawki le 18 Mai 2022
thank you, first option worked

Connectez-vous pour commenter.

Réponse acceptée

Davide Masiello
Davide Masiello le 18 Mai 2022
Just be aware of the fact that you do not need to use a loop to do this
A = 0:5:15
A = 1×4
0 5 10 15
That said, if you really must use a loop, then you could write
A = zeros(1,4);
for idx = 1:3
A(idx+1) = idx*5;
end
A
A = 1×4
0 5 10 15
I strongly recommend going with the first option.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by