필터 지우기
필터 지우기

How to Set Value of a Structure as Cell Array?

조회 수: 2 (최근 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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by