How to calculate mean on data from cell array of 3D struct array?

7 views (last 30 days)
I have cell array Data_output (dimensions 1x10), which contains 10 three-dimensional structures (dimension 7x6x2). Each element of this 7x6x2 structure array is a structure and the structure is same for all elements. I want to calculate mean value across columns of part of the structure Data_output{1}(:,6,1).dom_freq_PRSA_down where dom_freq_PRSA_down is in each structure matrix of freque
if true
mean(Data_output{1}(:,6,1).dom_freq_PRSA_down,1) % do not work, error
P1V6T10_allFiles = Data_output{1}(:,6,1).dom_freq_PRSA_down % does not retrieve all data
mean(P1V6T10_allFiles,1) % give not desired results, due to fact that it does not contain all data
endncies.
Firstly, i could not calculate mean(Data_output{1}(:,6,1).dom_freq_PRSA_down,1), i got error to many input arguments. Secondly, when i print Data_output{1}(:,6,1).dom_freq_PRSA_down it has much more rows than when i print P1V6T10_allFiles where P1V6T10_allFiles = Data_output{1}(:,6,1).dom_freq_PRSA_down. I can calculate mean(P1V6T10_allFiles,1) and it does not average across all values from Data_output{1}(:,6,1).dom_freq_PRSA_down so that is not what i need. Also, do you know how one can see what is the type of Data_output{1}(:,6,1).dom_freq_PRSA_down, is it a array, struct array, or something other
Thank you.
Do you have any suggestions what should i try?
  3 Comments
Jan
Jan on 21 Mar 2018
@Pawel: The message does not contain code, so there is nothing to format here. I do not see a need for a bullet list also.
Milica Svasta
Milica Svasta on 21 Mar 2018
I would like to rearrange it in any way that you think is easier to read. I think now it is even more ugly

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 21 Mar 2018
Edited: Stephen23 on 21 Mar 2018
cat(3,Data_output{1}(:,6,1).dom_freq_PRSA_down)
take the mean as appropriate, e.g.:
mean(...,2)
"do you know how one can see what is the type of Data_output{1}(:,6,1).dom_freq_PRSA_down, is it a array, struct array, or something other"
It is none of those because what you have defined is actually a comma-separated list, which is a list of separate individual variables. That is why you got the "too many arguments" error, because you provided mean with multiple separate inputs: this is not something that it appreciates. However you can easily concatenate those separate variables into one, as my answer shows. You can learn more about comma separated lists here:
  3 Comments
Stephen23
Stephen23 on 21 Mar 2018
Edited: Stephen23 on 21 Mar 2018
"Do you know how one can determined based on dimensionality if the data is it more appropriate to use struct-array or cell-array?"
Both cell arrays and structure arrays are both containers, so they can both store arbitrary data inside. The difference is really that cell arrays are accessed using indexing, whereas structure arrays use both indexing and fieldnames. Which one to use depends on your data, how it is stored, and how you are going to process it: fields are useful when the names add to understandability in the code, indexing keeps data in sequence and is very efficient.
To pick which one to use simply apply the same rule-of-thumb that you would for any other data variable: use the simplest class that stores your data and makes accessing it easy to understand. Simpler data classes are more efficient to access.
"They really did not look practical to use and i tried not to use them"
I find them very useful, and use them a lot with cell arrays and structure arrays.

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!