How to Set Value of a Structure as Cell Array?

4 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 5 月 12 日
コメント済み: Walter Roberson 2020 年 9 月 29 日
I have a structure, DLG.standard.Z1P and I have a cell array of data, C (2740x360). I would like to put this cell array within the structure DLG.standard.Z1P. I have three of these cell arrays that correspond to Z1P, and I would like to assign them such that the length of DLG.standard.Z1P is three, where Z1P has three cell arrays, each of size 2740x360. Any ideas on how to go about this?
I tried something like
DLG.standard.Z1P(1)=C
but that does not work.
Doing
DLG.standard.Z1P(1)=1;
DLG.standard.Z1P(2)=1;
does what I want it to, however, instead of 1, I want the whole cell array, C, in that location.

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 12 日
DLG.standard.Z1P{1} = C;
  3 件のコメント
Monica Nelson
Monica Nelson 2020 年 9 月 29 日
Can you do a similar thing for just one cell array and have it directly stored without sublevels?
I am trying to store data and identifiers in a structure and want to have the identifier (which the cell array 'expocode') at the same level as the data.
I have
D = struct('lon',longitude,'lat', latitude, 'expocode', expocode);
but D.expocode only gives the first value in the cell.
When I instead try the solution suggested above, ie.
D = struct('lon',longitude,'lat', latitude);
D.expocode{1}=expocode;
I get that D.expocode is a 1x1 cell array, rather than the contents of the cell array itself. How can I write this so that D.expocode is the cell array contents itself?
Thank you!
Walter Roberson
Walter Roberson 2020 年 9 月 29 日
Compare:
D = struct('lon',longitude,'lat', latitude, 'expocode', {expocode});
Provided that longitude and latitude are not cell arrays, then the result would be that D would be a scalar structure with fields lon and lat and expocode and the expocode field would be the full cell array expocode.
To:
D = struct('lon',longitude,'lat', latitude, 'expocode', expocode);
Provided that longitude and latitude are not cell arrays, then the result would be that D would be a non-scalar structure the same size as the cell array expocode, and D(K).lon would be a copy of longitude and D(K).lat would be a copy of the array latitude, and D(K).expocode would be a copy of expocode{K}
To:
D = struct('lon',longitude,'lat', latitude);
D.expocode = expocode;
Provided that longitude and latitude are not cell arrays, then the result would be that D would be a scalar structure with fields lon and lat and expocode and the expocode field would be the full cell array expocode. The result would be the same as the first syntax I showed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by