vector that displays [0 5 10 15]

i want a for loops that displays the following vector
[0 5 10 15]

3 Commenti

@Mahmoud Chawki - what have you tried so far? Do you want the for loop to build the array or just write the values to the console? Please clarify.
to build the vector
thank you, first option worked

Accedi per commentare.

 Risposta accettata

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.

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!

Translated by