Saving the average in each iteration of a for loop

1 view (last 30 days)
I have some data and I am trying to get a mean of 4 specific numbers for each row in an excel sheet. Some of my data looks like the below:
I want to save each mean for each row in a matrix "avgthic". My current code looks like this:
for i = 1:height(id)
edges= [athic(i,:), pthic(i,:), mthic(i,:), lthic(i,:)];
avgthic=mean(edgematrix, 'omitnan');
%This is averaging only the last row, not row 1, 2, and so on....
the "height(id)" is the height of column with the name of each element each measurement comes from, so I should have the same number of rows as I have id's. How would I get matlab to save each average for each row?

Answers (1)

KSSV on 28 Jul 2022
T = readtable(myfile) ;
data = table2array(T) ;
avgthic = mean(data,2,'omitnan')

Community Treasure Hunt

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

Start Hunting!