Find the average curve of multiple plots from different Excel files

2 ビュー (過去 30 日間)
Carla Baceanu
Carla Baceanu 2017 年 7 月 14 日
コメント済み: Carla Baceanu 2017 年 7 月 17 日
I have multiple excel files each having 2 columns, all numerical values. I have managed to make a plot which has all the lines superimposed, without actually extracting separate variables in the workspace. But now I need to find a line that is an average of all the other lines, and I can't figure it out. Might be more difficult since I don't have the variables extracted. This is the code. Thank you in advance!
Files = dir('E:\...');
N = length(Files);
for i = 3:N
m = sprintf('%s', Files(i,1).name);
Frequency = xlsread(m,'A:A');
Density = xlsread(m,'B:B');
plot(Density,Frequency)
hold on
xlabel('Density')
ylabel('Frequency')
xlim([0 1.4]);
ylim([0 7000]);
end

採用された回答

Sruthi Geetha
Sruthi Geetha 2017 年 7 月 17 日
You can find the sum of the frequency and density values for each file and then divide by N to get the mean of frequency and density respectively. Then plot them. It would look something like this:|
endFiles = dir('E:\...');
N = length(Files);
f = 0;
d = 0;
for i = 3:N
m = sprintf('%s', Files(i,1).name);
Frequency = xlsread(m,'A:A');
Density = xlsread(m,'B:B');
f = f + xlsread(m,'A:A');
d = d + xlsread(m,'B:B');
plot(Density,Frequency)
hold on
xlabel('Density')
ylabel('Frequency')
xlim([0 1.4]);
ylim([0 7000]);
end
fmean = f/N;
dmean = d/N;
plot(fmean,dmean);
hold off
  1 件のコメント
Carla Baceanu
Carla Baceanu 2017 年 7 月 17 日
Thank you, I follow the logic! How can I fix the problem if the number of rows are different? Files have different matrix sizes, and there is an error "matrix dimensions must agree"
f = f + xlsread(m,'A:A');
d = d + xlsread(m,'B:B');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by