Create structs with different number of columns

조회 수: 4 (최근 30일)
civil tech
civil tech 2020년 11월 4일
댓글: civil tech 2020년 11월 4일
Hi.
Assume that I have a parameter n, that has no constant value.
I want to cretae a single structure with n columns and m rows (m is constsnt) in each iteration of a loop. How can I do this? Note that in each loop, the parameter n is changed, so, the structures have no constant column.
Thanks in advance.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 11월 4일
This is not possible if you are referring to struct array and columns refers to the second dimension. For example if you had
s = struct('hello', 5);
s(1,5).hello = true;
Then you could not say that for s(2,:) you only want 3 columns.
You could store each struct inside a cell array.
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 11월 4일
When you want to access the K'th field, then fn{K} holds its name.
The code might be rather different if you had a small maximum bound on n making it practical to define allowed field names in advance
civil tech
civil tech 2020년 11월 4일
Thank you so much.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by