Determine the length of a 3D cell array (?) within a struct

1 view (last 30 days)
Hi together,
you find a MATLAB file in the dropbox-link, containing a 1x1 struct M:
This struct contains cell-arrays d00 to d15 (I'm not sure if these are cell arrays or something else). Each d** has three dimensions.
The first two dimensios are 3 and 4 (3x4). The third dimension is varying from d** to d**.
I want to extract the entries of the third dimension within a loop. Therefor I have to determine the lentgh of this third dimension for every d**.
Somebody can give me some advice?
Thanks a lot for help in advance! Ka Me

Accepted Answer

Jan
Jan on 17 Sep 2013
The solution would be trivial, if you avoid using "d00", "d01" etc as names of the variables. Hiding an index in the name is a very bad idea, which provokes such troubles. Better use a cell: d{1}, d{2}, ... Then:
dim3 = cellfun('size', d, 3)

More Answers (2)

Ka
Ka on 17 Sep 2013
Thanks a lot for the answer, Jan Simon.
You are right about the indexing within the name. However, I am using the program of someone else and I am not sure if I can manage to change the naming if it's a bit confusing.
What you suggest is making a cell array d with dimension 1x15, i.e. entries 0 to 14. Each entry contains a three dimensional matrix 3x4x?. Is this what you mean?
When I then use
dim3 = cellfun('size', d, 3)
Will I get the third dimension of each of the 15 d-entries?
If I am not able to change the naming, is there a another way doing it?
Thanks again!

Ka
Ka on 17 Sep 2013
I just found out that you can get the dimensions of this d-cell-arrays by dynamic adressing:
size(M.d**)
= 3 4 ...
Thanks for commenting again!

Community Treasure Hunt

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

Start Hunting!