필터 지우기
필터 지우기

How can I make the MarkerIndices automatic?

조회 수: 9 (최근 30일)
Jon
Jon 2020년 5월 22일
댓글: Jon 2020년 5월 22일
I have an issue with using the MarkerIndices property on a line. I want to selectively highlight a few points by changing the MarkerIndices value, then later restore the markers to all the points. If I add additional points to the line though, they don't have markers, since the MarkerIndices have been manually set. Is there a way to restore the MarkerIndices state to 'automatic' once it's been set manually?
This snippet demonstrates my issue. Create a line, highlight a point, restore the markers to all the points, then add more data to the line. Only the first 10 points end up with markers.
figure
H=plot(rand(1,10),rand(1,10),'ko-');
H.MarkerIndices=5;
drawnow
H.MarkerIndices=1:length(H.YData);
H.XData=[H.XData,rand(1,10)];
H.YData=[H.YData,rand(1,10)];

답변 (1개)

Steven Lord
Steven Lord 2020년 5월 22일
h = plot(1:10, 1:10, 'o-');
% Eliminate half the markers
h.MarkerIndices = 1:2:10;
% Change the number of points. No new markers appear.
v = 1:20;
set(h, 'XData', v, 'YData', v)
% Restore all the markers, old and new
h.MarkerIndices = 1:numel(h.XData);
  댓글 수: 1
Jon
Jon 2020년 5월 22일
Hi Steven, thank you for your response. This works, but if I add even more points, they won't have markers. If I never touched the MarkerIndices property in the first place, added points would get markers. Is there a way to restore that behavior after modifying MarkerIndices? I'm looking for something like MarkerIndicesMode='auto'.
This shows the issue:
h = plot(1:10, 1:10, 'o-');
% Eliminate half the markers
h.MarkerIndices = 1:2:10;
% Change the number of points. No new markers appear.
v = 1:20;
set(h, 'XData', v, 'YData', v)
% Restore all the markers, old and new
h.MarkerIndices = 1:numel(h.XData);
% Add even more points
v = 1:30;
set(h, 'XData', v, 'YData', v)
% The last 10 points don't have markers without resetting h.MarkerIndices

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by