create struct with nx1 dimension

83 ビュー (過去 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 Center および File ExchangeStructures についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by