Plot several signals but I want nudging or not overlap between them

23 vues (au cours des 30 derniers jours)
Hello,
I have ERG responses, different traces to graph in a Excel file. I have the time in seconds and in different sheets the data for 10 different intensities. I want to graphs all the intensities in the same plot, but they overlap. I want to put offset or a nudging but I can´t make it work. Here is the code I run.
filename = 'C:\Users\Milagros\Desktop\24 Hs\meangraphs.xls';
time = xlsread(filename,1,'A1:A512');
y1 = xlsread(filename,2,'A1:A512');
y2 = xlsread(filename,2,'B1:B512');
y3 = xlsread(filename,2,'C1:C512');
y4 = xlsread(filename,2,'D1:D512');
y5 = xlsread(filename,2,'E1:E512');
y6 = xlsread(filename,2,'F1:F512');
y7 = xlsread(filename,2,'G1:G512');
y8 = xlsread(filename,2,'H1:H512');
y9 = xlsread(filename,2,'I1:I512');
y10 = xlsread(filename,2,'J1:J512');
hold on
plot(time,[y1,y2,y3,y4,y5,y6,y7,y8,y9,y10]);
hold off
What I get in fig 1 and what I want is in fig 2.
  2 commentaires
Thorsten
Thorsten le 25 Nov 2015
Modifié(e) : Thorsten le 25 Nov 2015
You didn't ask for it, but you could probably make your life easier if you store the data in a single variable
ranges = 'A':'J';
for i=1:numel(ranges)
range = sprintf('%c1:%c512', ranges(i), ranges(i));
Y(:,i) = xlsread(filename,2,range);
end
Milagros ARIETTI
Milagros ARIETTI le 26 Nov 2015
Thank you. Is useful but since I need to separate each trace I don´t know how to do use it for this problem. But for other functions I wrote I can use it. So thank you.

Connectez-vous pour commenter.

Réponse acceptée

Mike Garrity
Mike Garrity le 25 Nov 2015
There are a couple of approaches.
If you want to put all of the plots in the same axes, then they're going to share the same Y scale. This means that to offset them, you need to actually modify their YData. That's actually pretty easy. Let's say youre starting with this:
theta = linspace(0,2*pi,400);
y1 = cos(theta);
y2 = cos(2*theta);
y3 = cos(3*theta);
y4 = cos(4*theta);
plot(theta,y1)
hold on
plot(theta,y2)
plot(theta,y3)
plot(theta,y4)
hold off
You'd just do something like this:
plot(theta,y1)
hold on
plot(theta,y2+2)
plot(theta,y3+4)
plot(theta,y4+6)
hold off
But then you need to manage the offsets yourself, and the YData and YTick values aren't "real".
The other way is to create separate Y scales. The plotyy function can create 2, but you want more than that, so you'll need to create your own axes. This requires a bit of bookkeeping. You need to do things like turn off the XTicks which would overlap other axes.
h = .815/4;
a1 = axes('Position',[.13 .11 .775 h])
plot(theta,y1)
a2 = axes('Position',[.13 .11+h .775 h])
plot(theta,y2)
a3 = axes('Position',[.13 .11+2*h .775 h])
plot(theta,y3)
a4 = axes('Position',[.13 .11+3*h .775 h])
plot(theta,y4)
set([a1, a2, a3, a4],'Box','off')
set([a2, a3, a4],'XTick',[])
  2 commentaires
Milagros ARIETTI
Milagros ARIETTI le 25 Nov 2015
Oh!! really thank you. I will try all, talk to the boss to see which one is better, but really thank you.
Milagros ARIETTI
Milagros ARIETTI le 26 Nov 2015
Thank you so much! the first and simple solutions looks nice! I will try the second one just to have more options to change things. But really thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by