Reputation: 1
I want to plot a dark green and a dark green dashed graph, but unfortunately MatLab complains that the vector does not have the same length
Error using plot
Vectors must be the same length.
Error in EasySim (line 174) `
plot(x,z1,'b--',x,z2,'c--',x,z3,'b',x,z4,'c',x,z5,'g',x,z6,'g--',x,z7,'color',[0 0.5 0],x,z8,'color',[0 0.5 0],'linestyle','--')
Upvotes: 0
Views: 7550
Reputation: 1587
As per this answer:
You cannot have more then one 'color', [R G B] in one plot statement.
You can change the colors after you've plotted them:
x = 0:4;
h = plot(x, x, '-', x, x.^2, '--');
set(h(1), 'color', [1 0 1])
set(h(2), 'color', [0 0.5 0])
Upvotes: 1
Reputation: 114
You cannot have more then one 'color', [R G B] in one plot statement.
so your code is like you write:
plot(x,z1,'b--',x,z2,'c--',x,z3,'b',x,z4,'c',x,z5,'g',x,z6,'g--',x,z7,'color',[0 0.5 0],x,z8,[0 0.5 0],'linestyle','--')
so the last line is x,z8,[0 0.5 0]. because x and z8 is not in length of 3 you got this error.
Note: if x and z8 is 3 elements each you got different error: Data must be a single matrix Y or a list of pairs X,Y.
you can check it on this example:
x=1:5
z1=x.^2;
z2=x.^3;
z3=x.^4;
z4=x.^5;
z5=x.^6;
z6=x.^7;
z7=x.^8;
z8=x.^9;
change x to x=1:3 to see what happen in this case
Upvotes: 1