vector that displays [0 5 10 15]

조회 수: 4 (최근 30일)
Mahmoud Chawki
Mahmoud Chawki 2022년 5월 18일
댓글: Mahmoud Chawki 2022년 5월 18일
i want a for loops that displays the following vector
[0 5 10 15]
  댓글 수: 3
Mahmoud Chawki
Mahmoud Chawki 2022년 5월 18일
to build the vector
Mahmoud Chawki
Mahmoud Chawki 2022년 5월 18일
thank you, first option worked

댓글을 달려면 로그인하십시오.

채택된 답변

Davide Masiello
Davide Masiello 2022년 5월 18일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by