plotyy error function,Vectors must be the same lengths.

5 visualizzazioni (ultimi 30 giorni)
Hi i want to plot a graph with two y-axes, the code shows me an error saying that : Error using plot Vectors must be the same lengths.
Error in C:\Program Files\MATLAB\R2012b\toolbox\matlab\graph2d\plotyy.p>fevalfun (line 342)
Error in C:\Program Files\MATLAB\R2012b\toolbox\matlab\graph2d\plotyy.p>plotyy (line 83)
Error in plotregimes (line 21)
[AX,H1,H2]=plotyy(t,z1,t,data,'bar','plot');
here is my code :
clear
clc
close all
delete *.asv
%addpath('C:\Users\ISSG\Desktop\PublishedCode\ToolKit')
load 'C:\Users\user\Desktop\PublishedCode\4regimes\st.txt'
z=st(:,4:end);
load 'C:\Users\user\Desktop\PublishedCode\4regimes\datain6.txt'
data=datain6(7:end,:);
z1=prctile(z==1,50);
z2=prctile(z==2,50);
z3=prctile(z==3,50);
z4=prctile(z==4,50);
t=1965+(7/12):1/12:2011+(3/12);
figure(1)
orient landscape
subplot(2,2,1);
[AX,H1,H2]=plotyy(t,z1,t,data,'bar','plot');
title('Probability of Regime 1');
set(AX(1),'xlim',[min(t) max(t)]);
set(AX(2),'xlim',[min(t) max(t)]);
set(AX(1),'ylim',[0 1]);
set(AX(2),'ylim',[min(min(data)) max(max(data))]);
set(AX(1),'Ycolor','b');
set(AX(2),'Ycolor','k');
subplot(2,2,2);
[AX,H1,H2]=plotyy(t,z2,t,data,'bar','plot');
title('Probability of Regime 2');
set(AX(1),'xlim',[min(t) max(t)]);
set(AX(2),'xlim',[min(t) max(t)]);
set(AX(1),'ylim',[0 1]);
set(AX(2),'ylim',[min(min(data)) max(max(data))]);
set(AX(1),'Ycolor','b');
set(AX(2),'Ycolor','k');
subplot(2,2,3);
[AX,H1,H2]=plotyy(t,z3,t,data,'bar','plot');
title('Probability of Regime 3');
set(AX(1),'xlim',[min(t) max(t)]);
set(AX(2),'xlim',[min(t) max(t)]);
set(AX(1),'ylim',[0 1]);
set(AX(2),'ylim',[min(min(data)) max(max(data))]);
set(AX(1),'Ycolor','b');
set(AX(2),'Ycolor','k');
subplot(2,2,4);
[AX,H1,H2]=plotyy(t,z4,t,data,'bar','plot');
title('Probability of Regime 4');
set(AX(1),'xlim',[min(t) max(t)]);
set(AX(2),'xlim',[min(t) max(t)]);
set(AX(1),'ylim',[0 1]);
set(AX(2),'ylim',[min(min(data)) max(max(data))]);
set(AX(1),'Ycolor','b');
set(AX(2),'Ycolor','k');
legend('Probability','Federal Funds Rate ','Bond Yield Spread','Unemployment rate','CPI Inflation','M2 growth','Stock Price growth');
print ../figure_files/RegimesFig -dpdf
  3 Commenti
haithem awijen
haithem awijen il 5 Nov 2018
Modificato: haithem awijen il 5 Nov 2018
here is the figure i would want to have
Walter Roberson
Walter Roberson il 5 Nov 2018
I would not recommend bar plot for this purpose. I would recommend using fill() to shade an area.

Accedi per commentare.

Risposte (3)

madhan ravi
madhan ravi il 2 Nov 2018
[AX,H1,H2]=plotyy(t(1:numel(z1)),z1,t(1:numel(data)),data,'bar','plot');
  4 Commenti
haithem awijen
haithem awijen il 5 Nov 2018
thank you so much, Here is the code , txt files and the figure deisred
haithem awijen
haithem awijen il 5 Nov 2018
i tried your sugesstions but it plot this figure:
clear
clc
close all
delete *.asv
load 'C:\Users\ISSG\Desktop\PublishedCode\4regimes\st.txt'
z=st(:,4:end);
load 'C:\Users\ISSG\Desktop\PublishedCode\4regimes\datain6.txt'
data=datain6(7:end,:);
z1=prctile(z==1,50);
z2=prctile(z==2,50);
z3=prctile(z==3,50);
z4=prctile(z==4,50);
t=1965+(7/12):1/12:2011+(3/12);
figure(1)
orient landscape
subplot(2,2,1);
title('Probability of Regime 1');
yyaxis left
plot(t,z1,'b');
yyaxis right
bar(t,z1)
subplot(2,2,2);
title('Probability of Regime 2');
yyaxis left
plot(t,z2,'b');
yyaxis right
bar(t,z2)
subplot(2,2,3);
title('Probability of Regime 3');
yyaxis left
plot(t,z3,'b');
yyaxis right
bar(t,z3)
subplot(2,2,4);
title('Probability of Regime 4')
yyaxis left
plot(t,z4,'b');
yyaxis right
bar(t,z4)
legend('Probability','Federal Funds Rate ','Bond Yield Spread','Unemployment rate','CPI Inflation','M2 growth','Stock Price growth');
end

Accedi per commentare.


haithem awijen
haithem awijen il 5 Nov 2018
it shows another error :
Index exceeds matrix dimensions.

haithem awijen
haithem awijen il 5 Nov 2018
here the code and txt file

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by