how to plot different range of files on one graph using hold on

2 ビュー (過去 30 日間)
shedrach
shedrach 2025 年 1 月 6 日
コメント済み: shedrach 2025 年 1 月 8 日
i have 63 .mat files that contain cells of data. i am dividing the .mat files into three parts so that each file is plotted correspondingly on the same graph from another set. that is, file 1 in the first, second third set are plotted on the same graph using hold on and the same for file 2 and so on. Although, i have not included the plot command, i am still trying to see how the code looks like by dividing the files into two sets.
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
count2 = 0;
filelist = dir('C:\Users\shedr\Downloads\tec data\2017\DOBUM\ttr\ttr1\tt4\*.mat');
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
spectrum = load(filelist(fileidx).name);
C = spectrum.B
% second set of files
for fileidx1 = startIndex1:endIndex1
count2 = count2+1;
if count2 == count1
spectrum1 = load(filelist(fileidx1).name);
C1 = spectrum.B
end
end
% but the output is not favourable.

採用された回答

Walter Roberson
Walter Roberson 2025 年 1 月 6 日
編集済み: Walter Roberson 2025 年 1 月 6 日
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
filelist = dir('C:\Users\shedr\Downloads\tec data\2017\DOBUM\ttr\ttr1\tt4\*.mat');
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
count2 = 0;
spectrum = load( fullfile(filelist(fileidx).folder, filelist(fileidx).name));
C = spectrum.B;
% second set of files
fileidx1 = startIndex1 + (fileidx - startIndex);
spectrum1 = load(fullfile(filelist(fileidx1).folder, filelist(fileidx1).name));
C1 = spectrum.B;
%do something with C and C1
plot(C, 'displayname', filelist(fileidx).name);
hold on
plot(C1, 'displayname', filelist(fileidx1).name);
end
hold off
legend('show')
  9 件のコメント
Walter Roberson
Walter Roberson 2025 年 1 月 7 日
startIndex = 1;
endIndex = 3;
startIndex1 = 4;
endIndex1 = 6;
count1 = 0;
filelist = dir('C:\Users\shedr\Downloads\tec data\2017\DOBUM\ttr\ttr1\tt4\*.mat');
% first set of files
for fileidx = startIndex:endIndex
count1 = count1+1;
count2 = 0;
spectrum = load( fullfile(filelist(fileidx).folder, filelist(fileidx).name));
C = spectrum.B;
% second set of files
fileidx1 = startIndex1 + (fileidx - startIndex);
spectrum1 = load(fullfile(filelist(fileidx1).folder, filelist(fileidx1).name));
C1 = spectrum.B;
%do something with C and C1
figure()
plot(C, 'displayname', filelist(fileidx).name);
hold on
plot(C1, 'displayname', filelist(fileidx1).name);
hold off
legend('show')
end
shedrach
shedrach 2025 年 1 月 8 日

Thank you. This last one got it

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by