How can I make the MarkerIndices automatic?

11 Ansichten (letzte 30 Tage)
Jon
Jon am 22 Mai 2020
Kommentiert: Jon am 22 Mai 2020
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)];

Antworten (1)

Steven Lord
Steven Lord am 22 Mai 2020
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 Kommentar
Jon
Jon am 22 Mai 2020
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by