How do I find peak duration with the following scatterplot?

1 次查看(过去 30 天)
I have a simple data sample taken from freshwater stream data. I have time plotted on x-axis and turbidity (pollution) plotted on y-axis. All I need to do is calculate the duration of each peak with a turbidity above 55 units.
clear
clc
load Time_X.txt
load Turbid_Y.txt
x=Time_X;
y=Turbid_Y;
t=[x,y];
i=1;
a=0;
b=0;
while b==0
if t(i,2)>=0
if y(i)>=55
a=a+1;
% disp(y(i))
value(a)=y(i);
end
i=i+1;
end
if i==14513
b=1;
end
end
scatter(x,y,'.')
hold on
plot([0 31], [55 55])
xlim([0 31]);
ylim([0 190]);
if y>55
disp('y')
end

采纳的回答

dpb
dpb 2017-6-5
load Time_X.txt
load Turbid_Y.txt
thrsh=55; % the threshold
ix=(Turbid_Y>thrsh); % locations above - use >= if GE desired instead of GT
crsPl=find([0 diff(ix)]== 1); % +ive crossing locations
crsMn=find([0 diff(ix)]==-1); % -ive crossing locations
dur=Time_X(crsPl)-Time_X(crsMn); % duration array
NB: The above assumes initial and final points in series are under threshold; iow, a number of "events" occur during the time record but not starting/ending in an event.
If that can be the case, check fo length() of the two crossings arrays being unequal and determine which is the start/end condition that doesn't match and process the matching pairs.
  3 个评论
dpb
dpb 2017-6-5
Dunno...that depends on what the file format is. I just copied that from your original presuming you had gotten that far already.
load is really designed/intended for .mat files which are Matlab-specific created by save altho it will read simple numeric-only files. If there's a header line, for example, that won't work.
You can try importdata that's more flexible but in the end you have to use a form to read the data that is compatible with the file format.
help iofun
will list the various options from which you can select one that seems most appropriate for the data you have. There's a section in the documentation "Ways to Import Text Files" that goes through the options available in more depth...
dpb
dpb 2017-6-5
"Error in graphing_script (line 16) load Time_X.txt"
Hmmm....line 16 seems peculiar; that'd be the very first line in the snippet I wrote; what's in the previous 15???

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by