Convert a vector into a structure array field

19 Ansichten (letzte 30 Tage)
bbb_bbb
bbb_bbb am 20 Okt. 2017
Kommentiert: bbb_bbb am 20 Okt. 2017
x= [2; 8; 6; 3; 7; 8];
for i=1:numel(x)
s(i).x=x(i);
end
Do the same, but without cycle.

Akzeptierte Antwort

Ray
Ray am 20 Okt. 2017
If struct s does not exist yet, you could use:
s = struct('x', num2cell(x));
  3 Kommentare
Walter Roberson
Walter Roberson am 20 Okt. 2017
if x is the same length as the number of entries in the struct array s, then
temp = num2cell(x);
[s.x] = temp{:};
bbb_bbb
bbb_bbb am 20 Okt. 2017
Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by