MATLAB: Plot multiple figures from the for loop in the same plot

.excel sheetsfigurefor loophold onmultiple plotsplot

Hi My data is in 5 sheets in a excel file. I want to plot data from each sheet in the same figure one over the another. But when I do this, it plots only the last sheet data. ??
%%Program to plot all data in one figure
clc
clear all
filename = 'data.xlsx';
sheetnames = { 'Sheet1','Sheet2','Sheet3','Sheet4','Sheet5' };
n = length(sheetnames);
for idx = 1:n
a = xlsread(filename,sheetnames{idx});
j=1:1:length(a);
Time_hr(j) = a(:,1);
Time_min(j) = a(:,2);
Time(j) = Time_hr(j)+ Time_min(j)/60;
freq(j)= a(:,3);
for j=1:1:length(idx)
plot (Time(j),freq(j));
end
end
Someone help me out .

Best Answer

figure ;
hold on
for idx = 1:n
a = xlsread(filename,sheetnames{idx});
j=1:1:length(a);
Time_hr(j) = a(:,1);
Time_min(j) = a(:,2);
Time(j) = Time_hr(j)+ Time_min(j)/60;
freq(j)= a(:,3);
for j=1:1:length(idx)
plot (Time(j),freq(j));
end
end
you have to use hold on..to plot multiple curves on the same plot.
Related Question