how to plot different range of files on one graph using hold on
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!