Why is a straight line being plotted at zero, in addition to my desired plot?

조회 수: 8 (최근 30일)
I'm plotting distance (X) versus different in duration of a sound signal across two different conditions (Y).
When I plot just the raw differences, I can plot several comparisons, plus a dotted black line at Y=0 for a reference (neg vs. pos differences).
When I try to plot those differences as percents (basically, (Y2-Y1)/Y1), I get a solid color line at Y=0, in addition to the black dotted one. If I plot one line at a time I can see that this straight colored line comes up even when I'm just plotting one of them.
Please see attached figure for comparison/illustration.
Parts of the respective codes (they are largely identical):
Raw differences
%Taking differences from Baseline
OneD10DegDiff=OneD10Deg-OneDBaseline;
OneD20DegDiff=OneD20Deg-OneDBaseline;
OneD30DegDiff=OneD30Deg-OneDBaseline;
OneD40DegDiff=OneD40Deg-OneDBaseline;
TwoD10DegDiff=TwoD10Deg-TwoDBaseline;
TwoD20DegDiff=TwoD20Deg-TwoDBaseline;
TwoD30DegDiff=TwoD30Deg-TwoDBaseline;
TwoD40DegDiff=TwoD40Deg-TwoDBaseline;
%Plot
hold on
plot(Data1D(:,1),OneD10DegDiff,'-r','LineWidth',2);
plot(Data1D(:,1),OneD20DegDiff,'-m','LineWidth',2);
plot(Data1D(:,1),OneD30DegDiff,'-g','LineWidth',2);
plot(Data1D(:,1),OneD40DegDiff,'-b','LineWidth',2);
plot(Data2D(:,1),TwoD10DegDiff,'-.r','LineWidth',2);
plot(Data2D(:,1),TwoD20DegDiff,'-.m','LineWidth',2);
plot(Data2D(:,1),TwoD30DegDiff,'-.g','LineWidth',2);
plot(Data2D(:,1),TwoD40DegDiff,'-.b','LineWidth',2);
plot([0,180],[0,0],':k','LineWidth',2);
axis([0 180 -0.25 0.1])
title([Name ' Percent Difference from Baseline'])
xlabel('Target Distance')
ylabel('Percent Duration Difference from Baseline (in ms)')
For percent differences:
%Taking differences from Baseline
OneD10DegDiff=(OneD10Deg-OneDBaseline)/OneDBaseline;
OneD20DegDiff=(OneD20Deg-OneDBaseline)/OneDBaseline;
OneD30DegDiff=(OneD30Deg-OneDBaseline)/OneDBaseline;
OneD40DegDiff=(OneD40Deg-OneDBaseline)/OneDBaseline;
TwoD10DegDiff=(TwoD10Deg-TwoDBaseline)/TwoDBaseline;
TwoD20DegDiff=(TwoD20Deg-TwoDBaseline)/TwoDBaseline;
TwoD30DegDiff=(TwoD30Deg-TwoDBaseline)/TwoDBaseline;
TwoD40DegDiff=(TwoD40Deg-TwoDBaseline)/TwoDBaseline;
%Plot
hold on
plot(Data1D(:,1),OneD10DegDiff,'-r','LineWidth',2);
plot(Data1D(:,1),OneD20DegDiff,'-m','LineWidth',2);
plot(Data1D(:,1),OneD30DegDiff,'-g','LineWidth',2);
plot(Data1D(:,1),OneD40DegDiff,'-b','LineWidth',2);
plot(Data2D(:,1),TwoD10DegDiff,'-.r','LineWidth',2);
plot(Data2D(:,1),TwoD20DegDiff,'-.m','LineWidth',2);
plot(Data2D(:,1),TwoD30DegDiff,'-.g','LineWidth',2);
plot(Data2D(:,1),TwoD40DegDiff,'-.b','LineWidth',2);
plot([0,180],[0,0],':k','LineWidth',2);
axis([0 180 -0.25 0.1])
title([Name ' Percent Difference from Baseline'])
xlabel('Target Distance')
ylabel('Percent Duration Difference from Baseline (in ms)')
  댓글 수: 1
Varun Lal
Varun Lal 2018년 6월 20일
Please help me out with this too.
t=data(:,1);
Ax=data(:,2);
Ay=data(:,3);
Az=data(:,4);
r=(Ax.^2 + Ay.^2 + Az.^2).^(1./2);
plot(t,Ax)
this is a plot of accleration vs time.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2014년 8월 19일
I don’t have your data and you didn’t describe it (I assume all are vectors), so see if doing the element-wise division makes a difference:
OneD10DegDiff=(OneD10Deg-OneDBaseline)./OneDBaseline;
Note the (./) in place of (/).
  댓글 수: 2
B.M.
B.M. 2014년 8월 19일
I knew it had to be something ridiculously simple like that. Haven't used those since I worked through an intro book a while ago. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrew Reibold
Andrew Reibold 2014년 8월 19일
편집: Andrew Reibold 2014년 8월 19일
You have the following line
plot([0,180],[0,0],':k','LineWidth',2);
This plots a line from 0 to 180, with values from 0 to 0. So it will leave a straight line at zero. If you didn't write that, it may just be a baseline for people to see where zero is :-)
If you remove it, does it still show up?
  댓글 수: 1
B.M.
B.M. 2014년 8월 19일
This is the black dotted line (format :k), which I did put in as a reference. I don't get where the colored line is coming from (cycles through red, magenta, green, then blue, so looks blue in the graphic). If I just plot the red line,
plot(Data1D(:,1),OneD10DegDiff,'-r','LineWidth',2);
This is what I get. (see attachment)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by