Marker Indices automation using 'set' function
19 次查看(过去 30 天)
显示 更早的评论
I have a script with a lot of plotting, and this involves markers which, howewer, have same parameters all over. Now, is there any way to streamline the code, so it doesn't have to repeat these lines all over and over again?
h = plot(49,8.4745,'o-','MarkerFaceColor','blue','MarkerEdgeColor','blue','MarkerIndices',1);
h = plot(50,21.4411,'o-','MarkerFaceColor','blue','MarkerEdgeColor','blue','MarkerIndices',1);
h = plot(50,39.5221,'o-','MarkerFaceColor','blue','MarkerEdgeColor','blue','MarkerIndices',1);
h = plot(50,76.2767,'o-','MarkerFaceColor','blue','MarkerEdgeColor','blue','MarkerIndices',1);
I tried to rewrite it into this
h1 = plot(x1,y1);
h2 = plot(x2,y2);
h3 = plot(x2,y3);
h4 = plot(x2,y4);
set([h1 h2 h3 h4],'o-','MarkerFaceColor','blue','MarkerEdgeColor','blue','MarkerIndices',1)
But I keep getting an error
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
0 个评论
采纳的回答
Steven Lord
2021-12-6
What you've written second would almost work if you turned hold on. However you can't use a line specification in a set call like you did. If you replaced 'o-' with 'Marker', 'o', 'LineStyle', '-' it should work.
x = 0:360;
h1 = plot(x, sind(x));
hold on
h2 = plot(x, sind(2*x));
set([h1 h2], 'Marker', 'o', 'MarkerIndices', 1:45:361)
Or you could write a function handle and use that function handle with your data as input.
plotMe = @(x, y) plot(x, y, 'Marker', 'o', 'MarkerIndices', 1:45:361);
figure
x = 0:360;
plotMe(x, sind(x));
hold on
plotMe(x, sind(2*x));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!