How do I average a 5-dimensional array?

Hi All,
I have a 5-D array that is 244 x 16 x 10 x 4 x 5, the '244 x 16' is data collected over time; the '10' is the number of trials; the '4' is number of experiments and the '5' is the number of participants. In other words, for every participant, I conducted 4 experiments, where I collected 10 trials of 244 x 16 data.
I would like to mean the number of trials for every experiment per participant, though I am having difficulty doing this. I have tried:
m = squeeze(mean(data,3)) %data is 244x16x10x4x5
However, when I plot the data (244 x 16) using a nested for loop (to plot per participant per experiment), my plots look completely off, suggesting that I may have averaged the data incorrectly.
Can someone please advise me if I have averaged my data incorrectly (I am assuming that I have)?
Thank you in advance

6 Comments

I don't see anything wrong with the MEAN command
If the plot is odd then your data is odd or the plot is wrong or you expectation is not right.
I only suspected that I calculated the mean incorrectly because when I average the trials for 1 experiment and 1 participant the plots look completely different to how I explained above.
You barely explain the plot is odd and tell us the size of your data. The trial is third dimension, so if you don't mix up the data, it should be correct.
If you want to persuade MEAN is wrong, you need to provide us the data and tell what you expect to get.
I wasn't trying to persuade the function mean was incorrect, I simply thought my execution of it was incorrect - but as you said it is not. So, I suppose the fault is somewhere else in my code. Anyway, thanks for your feedback.
One thing I would suggest is do not use SQUEEZE command, since you might find SQUEEZE does something you won't expect if one of dimension become scalar and you don't anticipate that to happens.
Use RESHAPE.
NA
NA on 15 Aug 2020
Edited: NA on 15 Aug 2020
Appreciate your feedback. I've only been using MATLAB for a few months, so there's quite a bit of a learning curve. I will take your advice on board and apply it on my current code, and use it for future reference. Thank you :)

Sign in to comment.

Answers (0)

Products

Release

R2019b

Asked:

NA
on 15 Aug 2020

Edited:

NA
on 15 Aug 2020

Community Treasure Hunt

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

Start Hunting!