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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by