Reshape Nx1 struct with field of Mx1 elements to N*Mx1 vector
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sabyrzhan Tasbolatov
il 22 Mag 2022
Commentato: Stephen23
il 22 Mag 2022
I have a struct A of [1000x1] size. There is a field "bar" which has [100x1] elements.
I want to have 1 variable, let's say B, which will be [1000*100x1] of "bar" elements.
How can I do it without iterating a struct and appending on some prepared zeroed vector? Can reshape do it?
1 Commento
Stephen23
il 22 Mag 2022
"How can I do it without iterating a struct and appending on some prepared zeroed vector? Can reshape do it?!
No, but a comma-separated list can do it:
Risposta accettata
Bruno Luong
il 22 Mag 2022
Modificato: Bruno Luong
il 22 Mag 2022
Something like
B = cat(1,A.bar)
0 Commenti
Più risposte (1)
MJFcoNaN
il 22 Mag 2022
This is an example:
bar=rand(100,1)
A=struct;
A.bar=bar;
% copy A.bar to all 1000 elements
A(2:1000,1)=A(1)
% table is a good intermediate form
tbl=struct2table(A);
B=cell2mat(cellfun(@transpose, tbl.bar, 'UniformOutput', false))
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!