Reshaping Structure in every iteration
Mostra commenti meno recenti
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 Commenti
Jan
il 8 Feb 2022
What do you call "structure"? A STRUCT array? A struct containing arrays as fields? Please post the current code.
mohammad rashidi
il 8 Feb 2022
Modificato: Jan
il 8 Feb 2022
Benjamin Thompson
il 8 Feb 2022
Modificato: Jan
il 8 Feb 2022
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
mohammad rashidi
il 8 Feb 2022
Jan
il 8 Feb 2022
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
mohammad rashidi
il 8 Feb 2022
Jan
il 8 Feb 2022
Okay, then I post this code as an answer.
Risposte (1)
Jan
il 8 Feb 2022
V = [];
for i = 1:10
V = cat(1, V, rand(5 + 10 * (i - 1), 1));
M(i).position = V ;
end
1 Commento
mohammad rashidi
il 9 Feb 2022
Categorie
Scopri di più su Logical 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!