Convert a vector into a structure array field

14 vues (au cours des 30 derniers jours)
bbb_bbb
bbb_bbb le 20 Oct 2017
Commenté : bbb_bbb le 20 Oct 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.

Réponse acceptée

Ray
Ray le 20 Oct 2017
If struct s does not exist yet, you could use:
s = struct('x', num2cell(x));
  3 commentaires
Walter Roberson
Walter Roberson le 20 Oct 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 le 20 Oct 2017
Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by