line vs. plot for plotting data

12 ビュー (過去 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 Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by