Reshaping Structure in every iteration

Hi
I'm iterating a loop. And in each iteration, i make random numbers by using rand function. And in every new iteration, I increase the size of matrix (which is created by rand function).
What i'm doing is storing every random matrix in structure in every iteration. So, what i need is to reshape the structure in every iteration.(to be Rows*1).
My question is, how can i reshape the structure ?
I'll really appreciate it if some one can help me with that.
Thanks a lot.

댓글 수: 7

Jan
Jan 2022년 2월 8일
What do you call "structure"? A STRUCT array? A struct containing arrays as fields? Please post the current code.
mohammad rashidi
mohammad rashidi 2022년 2월 8일
편집: Jan 2022년 2월 8일
R=5;
for i=1:10
M(:,i).position=rand(R,1);
R=R+10;
end
This is not what i'm working on , but that's similar.
Thank you.
Benjamin Thompson
Benjamin Thompson 2022년 2월 8일
편집: Jan 2022년 2월 8일
Your code seems to work. What specifically needs to be changed in the behavior?
>> R=5;
for i=1:10
M(:,i).position=rand(R,1);
R=R+10;
end
>> M
M =
1×10 struct array with fields:
position
As every random matrix has different rows, i want to gather all matrices in one matrix with the size of " rows*1 " at the end of each iteration.
It is still not clear. In each iteration only one matrix is created. What does "all matrices at the end of each iteration" mean then? What is "rows"? Do you want to append each new matrix to the existing one?
V = [];
for i = 1:10
V = cat(1, V, rand(5 + 10 * (i - 1), 1));
M(i).position = V ;
end
Exactly, i wanna append them. What i mean by " rows*1" is , i want to just have a final matrix with one column.
Jan
Jan 2022년 2월 8일
Okay, then I post this code as an answer.

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

답변 (1개)

Jan
Jan 2022년 2월 8일

1 개 추천

V = [];
for i = 1:10
V = cat(1, V, rand(5 + 10 * (i - 1), 1));
M(i).position = V ;
end

댓글 수: 1

Thank you Jan. It worked.
I really appreciate your help.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2022년 2월 8일

댓글:

2022년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by