MATLAB: How to create a for loop to calc average of datas in a STRUCTURE

averagesstructures

Hi, I have created a structure that splits my data with regards to specific loads. I was able to combine the repeats so all my data is in one structure.
I now want to calc averages so i can plot the data.
I have used
CoF1= [data_all{1, 2}(:, 5), data_all{1, 4}(:, 5), data_all{1, 6}(:, 5)]; %to have data together
CoF_av1 = mean(CoF1')'; %to get data across the rows
CoF_avall1 = mean(CoF1,'all'); %to get one average value fro all data
However as you can see the data splits up 10 times for this set and I would like to to create a for loop that will do it easier for me.
Therefore, my question is how would I create a loop to just average the 3 sets of data for me from within a structure.
So from the image I want to find out the average for each colum across each embedded structure-2, 4 and 6 column from 'data_all'.
Such that I am left with one data file that is the average of these 3, where each colum is a result of the average of my repeats. and then have an additional row that averages the column.

Best Answer

First, note that in matlab, a structure is particular data type. Here you're using structure with its non-matlab meaning. It can be a bit confusing. Your data is actually stored in a cell array.
Also note that mean(x')' is not a efficient way to calculate the mean across the rows. mean(x, 2) is a lot more efficient.
My initial reaction to your question is that the way you're storing your data is going to lead to complicated code and maybe we should be focusing on changing that rather than your actual question. In particular, I don't understand why you're repeating column 1 as column 3 and 5. You mention that you've grouped/split your data according to a criteria. Often it's better not to group/split the data and use a flatter storage format. If you explain in more details what you started with, we can look into that.
As it is, to do "Essentially i want to create another structure that is split in the same way. such that i have a column that is same as 1,3 and 5. I then want to create structure split this way but each little box includes 100*8 columns of Averages of the 3 datas i have", this is how I'd go about it:
%It is assumed that columns 1,3 and 5 are identical
assert(isequal(data_all(:, 1), data_all(:, 3)) && isequal(data_all(:, 3), data_all(:, 5)), 'Column 1,3 and 5 are not identical')
result = [data_all(:, 1), ...
cellfun(@(col2, col4, col6) mean(cat(3, col2, col4, col6), 3), ...
data_all(:, 2), data_all(:, 4), data_all(:, 6), ...
'UniformOutput', false)]