MATLAB: Add markers to stem plot above a threshold

markersstem plot

Hello,
I have a stem plot where I have removed all the markers. Now I want to add cross markers to the stems that exceed a certain threshold on the y-axis.
Is there a way to do that?

Best Answer

This would have to be done in two steps. First, create your stem plot with no markers, then plot a second stem plot on top of it for just the data that meets your requirements. Here's a simple example.
% Create your data. You will need x for the second plot.
x = 1:7;
y=[2 3 2 6 2 5 1];
% Find data points that exceed your threshold
ind = y>=5;
%Create the first stem plot. Specify the color to use in both stem plots
stem(x,y,"Marker","none",'Color','b')
% Add a second stem plot on top of the first.
hold on
stem(x(ind),y(ind),'Color','b','Marker',"x","LineStyle","none")
hold off
xlim([0,8])
ylim([0,8])