creating an ongoing matrix

Hello
The following simple script is going to merge two or three files and then calculate the mean of every n columns in a for loop. What I need to do is to create a new matrix as the number of averaged columns is added to the matrix one by one and write the resluts in an excel file. Thank you a lot in advance.
path='D:\';
fileName1=strcat(path,'Se1_101_200.xlsx'); %23*35 double
fileName2=strcat(path,'Se1_201_300.xlsx'); %23*35 double
data1 = xlsread(fileName1,2);
data2 = xlsread(fileName2,2);
mergedData1=[data1 data2]; %23*70 double
for i=1:35
for ii=36:70
B = mergedData1(:,[i ii]);
meanVal= mean(B,2);
% I need to create a matrix of 23*35 with the changing meanVal
end
end

7 件のコメント

Bob Thompson
Bob Thompson 2019 年 10 月 8 日
Index your output.
meanVal(:,i) = mean(B,2);
Or something like that.
Elaheh
Elaheh 2019 年 10 月 8 日
Thank you for your answer but could you be more specific and detailed? I am not an advanced user.
Zahra
Adam Danz
Adam Danz 2019 年 10 月 8 日
Could you explain in words what you're trying to do? Your ii-loop has 34 iterations and each of those iterations happen 35 times within your i-loop. That's 1190 iterations but your comment in the code suggest your're expecting 35 iterations.
Elaheh
Elaheh 2019 年 10 月 8 日
Hi
I have two data sets (each 23 rows *35 columns). I would like to average the corresponding columns of these two data sets (average 1st columns, average 2nd columns, etc) and then create one dataset that includes averages of the corresponding columns in the individual files.
Thank you
Adam Danz
Adam Danz 2019 年 10 月 8 日
To average the columns of a matrix,
mean(M,1)
Elaheh
Elaheh 2019 年 10 月 8 日
When I replaced "meanVal = mean(B,2);" with "meanVal(:,i) = mean(B,2);", I got a matrix with the desired size, but the problem was that in each iteration the values of all columns in meanVal were changed.
Bob Thompson
Bob Thompson 2019 年 10 月 9 日
Hmm, ok, I think I better understand what you're trying to do now. Just to reiterate though, you want the average of the first columns of each data set (columns 1 and 36) and then the average of the second columns of each data set (columns 2 and 37), but not the average of the non-corresponding columns (columns 1 and 37).
for i = 1:size(mergedData1,2)/2
B = mergedData1(:,[i i+size(mergedData1,2)/2]);
meanVal(:,i) = mean(B,2);
end

回答 (0 件)

この質問は閉じられています。

質問済み:

2019 年 10 月 8 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by