How to create array from saved iterations of a loop

조회 수: 25 (최근 30일)
Joseph McGorry
Joseph McGorry 2021년 8월 23일
댓글: Stephen23 2021년 8월 23일
I am wondering how I would create an array of numbers from a loop in matlab. After every iteration a number is saved and I want to be able to put all these outputs in one array. My outputs look like
x = 2
x = 3
x = 4
and so on.....
I want it so at the end of the loop the answer says
x = [2,3,4]
Thank you in advance

채택된 답변

Joseph McGorry
Joseph McGorry 2021년 8월 23일
For anyone wondering, initialise
x = [];
and then to call it outside the loop
x = [x,y]

추가 답변 (1개)

Awais Saeed
Awais Saeed 2021년 8월 23일
Just store them column by column
for jj = 1:1:5
x(jj) = jj
end
  댓글 수: 2
Joseph McGorry
Joseph McGorry 2021년 8월 23일
this doesn't work for me because it just keeps iterating over heaps changing variables
Awais Saeed
Awais Saeed 2021년 8월 23일
I do not know how your code is working but if you are getting values saved (as you said in question) then you should be able to save them as arrays

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

카테고리

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