简体   繁体   English

选择并绘制高于阈值的值

[英]Select and plot value above a threshold

I have a plot in which there are a few noise components. 我有一个图中有一些噪声成分。 I am planning to select data from that plot preferably above a threshold in my case I am planning to keep it at 2.009 on the Y axis. 我打算从该图中选择数据,最好是在阈值以上,我打算将其在Y轴上保持在2.009。 And plot the lines going only above it. 并绘制仅在其上方的线。 And if anything is below that i would want to plot it as 0. as we can see in the figure 如果下面有任何内容,我希望将其绘制为0。如图所示

在此处输入图片说明

t1=t(1:length(t)/5);  
t2=t(length(t)/5+1:2*length(t)/5);
t3=t(2*length(t)/5+1:3*length(t)/5);
t4=t(3*length(t)/5+1:4*length(t)/5);
t5=t(4*length(t)/5+1:end);
X=(length(prcdata(:,4))/5);
a = U(1 : X);
b = U(X+1: 2*X);
c = U(2*X+1 : 3*X);
d = U(3*X+1 : 4*X);
e = U(4*X+1 : 5*X);
figure;
subplot (3,2,2)
plot(t1,a);
subplot (3,2,3)
plot(t2,b);   
subplot(3,2,4)
plot(t3,c);
subplot(3,2,5)
plot(t4,d);
subplot(3,2,6)
plot(t5,e);
subplot(3,2,1)
plot(t,prcdata(:,5));
figure;
A=a(a>2.009,:);
plot (t1,A);

This code splits the data (in the image into 5 every 2.8 seconds, I am planning to use the thresholding in first 2.8 seconds. Also I had another code but I am just not sure if it works as it took a long time to be analysed 此代码将数据分割(在图像中,每2.8秒将其分成5个,我打算在前2.8秒中使用阈值。另外,我还有另一个代码,但是我不确定它是否有效,因为需要花费很长时间进行分析

figure;
A=a(a>2.009,:);
plot (t1,A);
for k=1:length(a)
    if a(k)>2.009
        plot(t1,a(k)), hold on
    else 
        plot(t1,0), hold on
    end
end
hold off

The problem is that you are trying to plot potentially several thousand times and adding thousands of points onto a plot which causes severe memory and graphical issues on your computer. 问题是您试图绘制潜在的数千次绘图,并将数千个点添加到绘图上,这会导致计算机上出现严重的内存和图形问题。 One thing you can do is pre process all of the information and then plot it all at once which will take significantly less time. 您可以做的一件事是预处理所有信息,然后一次绘制所有信息,这将大大减少时间。

figure
threshold = 2.009;
A=a>threshold; %Finds all locations where the vector is above your threshold
plot_vals = a.*A; %multiplies by logical vector, this sets invalid values to 0 and leaves valid values untouched
plot(t1,plot_vals)

Because MATLAB is a highly vectorized language, this format will not only be faster to compute due to a lack of for loops, it is also much less intensive on your computer as the graphics engine does not need to process thousands of points individually. 由于MATLAB是一种高度矢量化的语言,由于缺少for循环,该格式不仅计算速度更快,而且由于图形引擎不需要单独处理数千个点,因此在计算机上的使用强度也大大降低。

The way MATLAB handles plots is with handles to each line. MATLAB处理图的方式与每条线的处理相同。 When you plot a vector, MATLAB is able to simply store the vector in one address and call it once when plotting. 绘制矢量时,MATLAB能够将矢量简单地存储在一个地址中,并在绘制时调用一次。 However, when each point is called individually, MATLAB has to store each point in a separate location in memory and call all of them individually and graphically handle each point completely separately. 但是,当单独调用每个点时,MATLAB必须将每个点存储在内存中的单独位置,然后分别调用所有它们,并以图形方式完全独立地处理每个点。

Per request here is the edit plot(t1(A),plot_vals(A)) 每个请求在这里是编辑图(t1(A),plot_vals(A))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM