create struct with nx1 dimension

69 visualizaciones (últimos 30 días)
Marc Janousek
Marc Janousek el 6 de En. de 2020
Comentada: Marc Janousek el 6 de En. de 2020
Hi !
I am looking for a way to create an empty struct with the dimensions 2x1.
So far i only know the comment
StructName = struct
which creates a struct with the dimensions 1x1
Thank you very much in advance!
Marc
  2 comentarios
Stephen23
Stephen23 el 6 de En. de 2020
Editada: Stephen23 el 6 de En. de 2020
A struct with size 2x1 is not empty, it has two elements.
Empty means that at least one dimension has zero size.
The number of fields a structure has is unrelated to its size.
You can easily create a 2x1 (i.e. not empty) structure with no fields:
S = repmat(struct(),2,1)
Marc Janousek
Marc Janousek el 6 de En. de 2020
Thank you Stephen! That got me on the right path!

Iniciar sesión para comentar.

Respuesta aceptada

Max Murphy
Max Murphy el 6 de En. de 2020
StructName = struct('FieldName1',cell(2,1),'FieldName2',cell(2,1));
% or
StructName = struct('FieldName1',[],'FieldName2',[]);
StructName = repmat(StructName,2,1);
  1 comentario
Marc Janousek
Marc Janousek el 6 de En. de 2020
Thank you very much! Your input helped me a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by