how to plot different range of files on one graph using hold on
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shedrach
el 6 de En. de 2025
Comentada: shedrach
el 8 de En. de 2025
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 comentarios
Respuesta aceptada
Walter Roberson
el 6 de En. de 2025
Editada: Walter Roberson
el 6 de En. de 2025
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 comentarios
Walter Roberson
el 7 de En. de 2025
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!