Borrar filtros
Borrar filtros

Convert a vector into a structure array field

27 visualizaciones (últimos 30 días)
bbb_bbb
bbb_bbb el 20 de Oct. de 2017
Comentada: bbb_bbb el 20 de Oct. de 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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by