create struct with nx1 dimension

조회 수: 71 (최근 30일)
Marc Janousek
Marc Janousek 2020년 1월 6일
댓글: Marc Janousek 2020년 1월 6일
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
Stephen23
Stephen23 2020년 1월 6일
편집: Stephen23 2020년 1월 6일
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 2020년 1월 6일
Thank you Stephen! That got me on the right path!

댓글을 달려면 로그인하십시오.

채택된 답변

Max Murphy
Max Murphy 2020년 1월 6일
StructName = struct('FieldName1',cell(2,1),'FieldName2',cell(2,1));
% or
StructName = struct('FieldName1',[],'FieldName2',[]);
StructName = repmat(StructName,2,1);
  댓글 수: 1
Marc Janousek
Marc Janousek 2020년 1월 6일
Thank you very much! Your input helped me a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by