Marker Indices automation using 'set' function
조회 수: 23 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!