Plot multiple figures from the for loop in the same plot

2 Ansichten (letzte 30 Tage)
Add
Add am 19 Mai 2016
Kommentiert: Add am 19 Mai 2016
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 .

Akzeptierte Antwort

KSSV
KSSV am 19 Mai 2016
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.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by