Why will these plots not plot on the same graph?

4 vues (au cours des 30 derniers jours)
Reid Johnson
Reid Johnson le 15 Sep 2019
I think that matlab thinks the data has different axes for each plot, even though all the data has the same two axes. I get the data that im plotting from a matrix that I create earlier in the code. The columns are set up in a way that if column x is my x values, column x+1 is my y values, where x is an odd number. If I comment out the red graph, the green is plotted. If I comment out the green and red graph, the blue is plotted.
clc; clear;
load('rpm_kw.mat')
x=1;i=1;
rpmcol=1;
[m,n]=size(rpm_kw);
while rpmcol<=m-3
Astop=1;
conf=0;
while conf==0 %getting set A
if isnan(rpm_kw(Astop,rpmcol)) || isnan(rpm_kw(Astop,rpmcol+1)) %finding length of set A by running until nan
Astop=Astop-1; %location of the last value in set A
spdnpwr(1:Astop,x)=rpm_kw(1:Astop,rpmcol); %writing rpm values for set A
spdnpwr(1:Astop,x+1)=rpm_kw(1:Astop,rpmcol+1); %writing pwr values for set A
conf=1; %confirms set A values have been written to spdnpwr
else
Astop=Astop+1; %Increase Astop (done until NaN is found)
end
end
Bstop=1;
conf=0;
while conf==0 %getting set B
if isnan(rpm_kw(Bstop,rpmcol)) || isnan(rpm_kw(Bstop,rpmcol+1)) %finding length of set B by running until nan
Bstop=Bstop-1; %location of the last value in set B
spdnpwr(1:Bstop,x+2)=rpm_kw(1:Bstop,rpmcol); %writing rpm values for set B
spdnpwr(1:Bstop,x+3)=rpm_kw(1:Bstop,rpmcol+1); %writing pwr values for set B
conf=1; %confirms set B values have been written to spdnpwr
else
Bstop=Bstop+1; %Increase Bstop (done until NaN is found)
end
end
Cstop=Astop+Bstop;
y=1;a=1;b=1;
while y<=Cstop %getting set C
if spdnpwr(a,x)<spdnpwr(b,x+2) %if set A is less than set B, use set A for current set C value
spdnpwr(y,x+4)=spdnpwr(a,x); %rpm
spdnpwr(y,x+5)=spdnpwr(a,x+1); %pwr
a=a+1;
elseif spdnpwr(b,x+2)<spdnpwr(a,x) %if set B is less than set A, use set B for current set C value
spdnpwr(y,x+4)=spdnpwr(b,x+2); %rpm
spdnpwr(y,x+5)=spdnpwr(b,x+3); %pwr
b=b+1;
elseif spdnpwr(a,x)==spdnpwr(b,x+2) %if set B is equal to set A
if spdnpwr(a,x+1)<spdnpwr(b,x+3) %if set A pwr is less than set B, use set A for current set C value
spdnpwr(y,x+4)=spdnpwr(a,x); %rpm
spdnpwr(y,x+5)=spdnpwr(a,x+1); %pwr
a=a+1;
elseif spdnpwr(b,x+3)<spdnpwr(a,x+1) %if set B pwr is less than set A, use set B for current set C value
spdnpwr(y,x+4)=spdnpwr(b,x+2); %rpm
spdnpwr(y,x+5)=spdnpwr(b,x+3); %pwr
b=b+1;
elseif spdnpwr(a,x+1)==spdnpwr(b,x+3) %if set A pwr is equal to set B, use set A for current set C value and set B for next C value
spdnpwr(y,x+4)=spdnpwr(a,x); %rpm
spdnpwr(y,x+5)=spdnpwr(a,x+1); %pwr
spdnpwr(y+1,x+4)=spdnpwr(b,x+2); %rpm
spdnpwr(y+1,x+5)=spdnpwr(b,x+3); %pwr
a=a+1;b=b+1;y=y+1;
else
disp('You mucked up')
end
end
y=y+1;
end
%temp plots
subplot(4,4,i)
plot(spdnpwr(1:Astop,x),spdnpwr(1:Astop,x+1),'b')
plot(spdnpwr(1:Bstop,x+2),spdnpwr(1:Bstop,x+3),'g')
plot(spdnpwr(1:Cstop,x+4),spdnpwr(1:Cstop,x+5),'r')
xlabel('rpm')
ylabel('kw')
i=i+1;
rpmcol=rpmcol+4;
x=x+6;
end

Réponses (1)

Jim Riggs
Jim Riggs le 15 Sep 2019
Modifié(e) : Jim Riggs le 15 Sep 2019
You need to turn on "hold" mode to plot more than one plot on the same axes. If you do not use hold, the next plot replaces the previous one.
plot(...'b');
hold on;
plot(... 'g');
plot(... 'r');
  1 commentaire
Reid Johnson
Reid Johnson le 15 Sep 2019
I've tried using hold before but it didn't work. I'll try again and put it in the location you have it in.
The only success I've had is using yyaxis, but that gives undesirable results.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by