Marker Indices automation using 'set' function
20 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Steven Lord
on 6 Dec 2021
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));
2 Comments
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!