line vs. plot for plotting data
조회 수: 28 (최근 30일)
이전 댓글 표시
I ran across a difference between line objects when using the line vs. plot commands for plotting data. When I attempt to set the SeriesIndex property of a line created with the line command, I get an unrecognized property error.
x = 0:10;
y = x.^2;
figure
lh1 = line(x,y,'SeriesIndex',2);
However, if I create a line with the plot command, the SeriesIndex property works as stated in the MATLAB documentation for Line Properties.
x = 0:10;
y = x.^2;
lh2 = plot(x,y,'SeriesIndex',2);
Even though these two objects are both Line objects with almost identical properties, it seems that the object created with the line command is of the class 'matlab.graphics.primitive.Line', whereas the object created with the plot command is of the class 'matlab.graphics.chart.primitive.Line'. I never realized there was a difference between a line created with the line command vs. the plot command. I wonder if the omission of the SeriesIndex property for the former is intentional. And if so, what is the reason for the different primitives? Are there differences between these two objects that would suggest using one method over the other in certain cases?
댓글 수: 0
채택된 답변
the cyclist
2023년 2월 6일
I would be confident that the difference is intentional, based on the two documentation pages for the primitive line and the chart line.
It seems sensible to me that lines that are known to be part of a chart would carry more properties (that would be superfluous in a single primitive line). SeriesIndex is just one of them, as you can see from the pages I linked.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!