MATLAB: I have a matrix of dimension 180×41 double. First column of the matrix is SubjectID, rest columns are four scores for 10 segments. I need to calculate mean of four scores for each part and store in one matrix. Please Help!

iterate through rows of a matrix

The output should look like as:
SUbID MSE1_S1(Mean) MSE2_S2(Mean) MSE3_S3(Mean)…… where MSE1_S1 = mean(MSE_1_S1,MSE_1_S2,MSE_1_S3,MSE_1_S4)

Best Answer

data = dlmread('MSE_cl_Fz.csv',',',1,2);
ind_s = 1:4:size(data,2);
ind_e = 4:4:size(data,2);
for row_no = 1:size(data,1)
mean_arr(row_no,:) = arrayfun(@(a,b) mean(data(row_no,a:b)),ind_s,ind_e);
end