Convert a vector into a structure array field
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
x= [2; 8; 6; 3; 7; 8];
for i=1:numel(x)
s(i).x=x(i);
end
Do the same, but without cycle.
0 Commenti
Risposta accettata
Ray
il 20 Ott 2017
If struct s does not exist yet, you could use:
s = struct('x', num2cell(x));
3 Commenti
Walter Roberson
il 20 Ott 2017
if x is the same length as the number of entries in the struct array s, then
temp = num2cell(x);
[s.x] = temp{:};
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!