# How to Set Value of a Structure as Cell Array?

2 views (last 30 days)
Ibro Tutic on 12 May 2017
Commented: Walter Roberson on 29 Sep 2020
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 on 12 May 2017
DLG.standard.Z1P{1} = C;
Walter Roberson on 29 Sep 2020
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.