I want to produce a plot with two y-axis and apply multiple datasets to one of the axis. For example
[hAx,hLine1,hLine2] = plotyy([x1',x2',x3'],[y1',y2',y3'],x4,y4);
where x1
and y1
are 1000x1
-arrays, x2
and y2
are 2000x1
-arrays and x3
and y3
are 3000x1
-arrays. The range of the arrays is more or less the same. When i try producing this plot, MATLAB gets me an error saying
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Is there any workaround for this error?
EDIT: Here's my real code, which is not working:
[hAx,hLine1,hLine2] = plotyy([erg_cm.Time.data,erg_cm.Time.data,t',t'],...
[erg_cm.Car_FxFL.data,erg_cm.Car_FxFR.data,Fx(1,:),Fx(2,:)],...
erg_cm.Time.data,diff);
And my original data:
erg_cm.Time.data
is 1x4001
t
is 80300x1
erg_cm.Car_FxFL.data
is 1x4001
erg_cm.Car_FxFR.data
is 1x4001
Fx
is 4x80300
diff
is 1x4001
Your x
and y
vectors are column vectors and you're trying to concatenate them horizontally, which you cannot do because they are not the same size. You want to vertically concatenate them:
[hAx,hLine1,hLine2] = plotyy([x1;x2;x3],[y1;y2;y3],x4,y4);
EDIT: This is what I'm testing with
erg_cm.Time.data = rand(1, 4001);
t = rand(80300, 1);
erg_cm.Car_FxFL.data = rand(1, 4001);
erg_cm.Car_FxFR.data = rand(1, 4001);
Fx = rand(4, 80300);
diff = rand(1, 4001);
[hAx,hLine1,hLine2] = plotyy([erg_cm.Time.data,erg_cm.Time.data,t',t'],...
[erg_cm.Car_FxFL.data,erg_cm.Car_FxFR.data,Fx(1,:),Fx(2,:)],...
erg_cm.Time.data,diff);