Different line types for multiple curves

조회 수: 6 (최근 30일)
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen 2021년 4월 9일
Hi MATLAB Community,
How would I change the line type for my plot, so I have a '-r' and '--r' as well as '-b' and '--b'?
figure;
p = plot(x, y);
set(p, {'color'}, {'r'; 'r'; 'b'; 'b'});

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 9일
Maybe you'll have to accept looping a little:
lstl = {'-','--'};
for i1 = 1:4,
set(p(i1),'linestyle',lstl{rem(i1,2)+1})
end
HTH
  댓글 수: 1
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen 2021년 4월 9일
Thanks, no the best at looping yet, but it worked great.

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

추가 답변 (1개)

VBBV
VBBV 2021년 4월 9일
편집: VBBV 2021년 4월 9일
%f true
figure;
p = plot(x, y);
set(p, {'LineStyle'},{'-';'--';'-';'--'},{'color'}, {'r'; 'r'; 'b'; 'b'});
  댓글 수: 1
Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 9일
Neat, but:
Mathworks, this is ugly!
When I tried this:
set(p, 'LineStyle',{'-';'--';'-';'--'},{'color'}, {'r'; 'r'; 'b'; 'b'});
I got and angry error-message:
Error using matlab.graphics.chart.primitive.Line/set
Error setting property 'LineStyle' of class 'Line':
Invalid enum value. Use one of these values: '-' | '--' | ':' | '-.' | 'none'.
...but when wrapping the property in a cell-array everything works fine. That is ugly.

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by