I have a matrix of data which I am trying to analyse. I have a data and I applied some processing part and I managed to get some information below a certain level as in trying to apply threshold to it. So after I applied threshold the data goes to 0 point. So I was wondering if there was a way to just eliminate the points without it leaving 0 in between. This is what the figure looks like with the zeros in that I was trying to plot it without the gap the X Axis is time, y axis is amplitude. So will that be possible to just plot the events which are in blue and the time together?
%Find time
N = size(prcdata(:,1),1);
t=T*(0:N-1)';
figure;
plot(t,U);
t1=t(1:length(t)/5);
X=(length(prcdata(:,4))/5);
a = U(1 : X);
threshold=3.063;
A=a>threshold;
plot_vals=a.*A;
figure;
plot(t2,plot_vals1); %gives the plot which i added with this
I also tried this code to club the events without the zeros but all it gives me is a straight line plot at 0.
%% Eliminate the rows and colomns which are zero
B1=plot_vals1(plot_vals1 <= 0, :);
figure;
plot(B1);
Also is there any way to take the scatter of the figure above? Will using scatter(t2,plot_vals1); work?
If you want to only display those points that are above your threshold, you can use a logical index and set the value of the unwanted points to NaN
:
threshold = 3.063;
index = (a <= threshold);
a(index) = NaN;
figure;
plot(t1, a);
Data points that are NaN
simply won't be displayed, leaving a break in your plot. Here's a simple example that plots the positive points of a sine wave in red:
t = linspace(0, 4*pi, 100);
y = sin(t);
plot(t, y)
hold on;
index = (y < 0);
y(index) = nan;
plot(t, y, 'r', 'LineWidth', 2);