How to plot a dark green graph with RGB indication?

조회 수: 659 (최근 30일)
Michael Gaida
Michael Gaida 2018년 3월 1일
댓글: Walter Roberson 2019년 8월 7일
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','--')

답변 (2개)

Emily
Emily 2019년 8월 6일
If you want different lines to have different properties, you can plot them with separate lines of code, using 'hold on'.
plot(x,z1,'color',[0 0.5 0],'linestyle','--');
hold on
plot(x,z2,'color',[0 0.5 0],'linestyle','-');
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 8월 7일
True -- but in the case where you are using the same color and only changing the linestyle (your example) then you can use a linespec:
plot(x, z1, '--', x, z2, '-', 'color', [0 0.5 0]) %name/value pairs apply to all the plots

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


Tony Mohan Varghese
Tony Mohan Varghese 2018년 3월 19일
plot(_,Name,Value) specifies line properties using one or more Name,Value pair arguments. Name-value pair settings apply to all the lines plotted.
Please refer to the documentation of plot: https://in.mathworks.com/help/matlab/ref/plot.html
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 3월 19일
Also, the name-value pairs must go after all of the x, y, linespec items -- which is probably why you are receiving the error.

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

카테고리

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