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

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

Could you please re-write your question using the formatting tools provided? Use 'code' for 'code' and bullet points for questions/explanation what you've done so far?
@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.
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

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

Your link to your other answer was really useful. Just if i knew that this is my problem, i would not asked the question. I have just changed
cat(1,Data_output{1}(:,6,1).dom_freq_PRSA_down)
mean(...,1)
and it produces exactly what i want. Couple of days ago, i have bump into comma-separated lists on this site and it was probably your post. They really did not look practical to use and i tried not to use them. Only way i can skip them is instead cell array i use Data_output as struct-array. Do you know how one can determined based on dimensionality if the data is it more appropriate to use struct-array or cell-array? I do not see clear difference between these structures. Thank you.
"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

Community Treasure Hunt

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

Start Hunting!