http://www.mathworks.com/matlabcentral/newsreader/view_thread/322449
MATLAB Central Newsreader  how can one index into a cell array of structs?
Feed for thread: how can one index into a cell array of structs?
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 10 Aug 2012 13:11:11 +0000
how can one index into a cell array of structs?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/322449#885057
Kirk
I am trying to produce a map of climate values that are stored in a cell array of structures. For example, from the cell array {}Clim<79x133>, I can retrieve all of a single cell's maximum temperatures (which is a 13680x1 double) with:<br>
<br>
Clim{1,1}.tmax<br>
<br>
This command gives me all 13680 maximum temperature values from the element tmax. I need to grab a single value for that element for all cells in the array (let's say the last value, number 13680 from all cells)...<br>
<br>
I have tried things like <br>
<br>
Clim{:,:}.tmax(1360,:)<br>
<br>
to no avail...<br>
<br>
Can anyone suggest an approach? <br>
<br>
Thanks in advance

Fri, 10 Aug 2012 13:26:08 +0000
Re: how can one index into a cell array of structs?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/322449#885063
Kirk
"Kirk" <kwythers.nospam@umn.edu> wrote in message <k0319f$okg$1@newscl01ah.mathworks.com>...<br>
> I am trying to produce a map of climate values that are stored in a cell array of structures. For example, from the cell array {}Clim<79x133>, I can retrieve all of a single cell's maximum temperatures (which is a 13680x1 double) with:<br>
> <br>
> Clim{1,1}.tmax<br>
> <br>
> This command gives me all 13680 maximum temperature values from the element tmax. I need to grab a single value for that element for all cells in the array (let's say the last value, number 13680 from all cells)...<br>
> <br>
> I have tried things like <br>
> <br>
> Clim{:,:}.tmax(1360,:)<br>
> <br>
> to no avail...<br>
> <br>
> Can anyone suggest an approach? <br>
> <br>
> Thanks in advance<br>
<br>
<br>
God am I dense... It seems that I asked this very question 6 months ago. MattJ kindly provided a solution:<br>
<br>
tmax_1 = arrayfun(@(i) ClimIn{i}.tmax(1), 1:numel(ClimIn)); <br>
tmax_1 = reshape(tmax_1, size(ClimIn));<br>
<br>
Works well. Sorry

Fri, 10 Aug 2012 13:44:14 +0000
Re: how can one index into a cell array of structs?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/322449#885068
Justin Ashmall
Having a cell array of structs is a bit tricky. Are the structs all different?<br>
<br>
If not, having a (regular) array of structs would be much more flexible, if that's possible.<br>
<br>
j(1).tmax = rand(100,1);<br>
j(2).tmax = rand(100,1);<br>
j(3).tmax = rand(100,1);<br>
all_tmax = [j.tmax];<br>
size(all_tmax)<br>
ans =<br>
100 3<br>
<br>
Then use all_tmax as normal. If j (or Clim in your example) is 2d, you might need to use reshape() on all_tmax.<br>
<br>
Having said that, if the tmax fields are all different sizes then you're stuck.<br>
<br>
Justin<br>
<br>
<br>
"Kirk" <kwythers.nospam@umn.edu> wrote in message <k0319f$okg$1@newscl01ah.mathworks.com>...<br>
> I am trying to produce a map of climate values that are stored in a cell array of structures. For example, from the cell array {}Clim<79x133>, I can retrieve all of a single cell's maximum temperatures (which is a 13680x1 double) with:<br>
> <br>
> Clim{1,1}.tmax<br>
> <br>
> This command gives me all 13680 maximum temperature values from the element tmax. I need to grab a single value for that element for all cells in the array (let's say the last value, number 13680 from all cells)...<br>
> <br>
> I have tried things like <br>
> <br>
> Clim{:,:}.tmax(1360,:)<br>
> <br>
> to no avail...<br>
> <br>
> Can anyone suggest an approach? <br>
> <br>
> Thanks in advance