line vs. plot for plotting data

조회 수: 28 (최근 30일)
Andrew Rockhill
Andrew Rockhill 2023년 2월 6일
답변: the cyclist 2023년 2월 6일
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);
Error using line
Unrecognized property SeriesIndex for class Line.
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?

채택된 답변

the cyclist
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개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by