How do I find peak duration with the following scatterplot?

조회 수: 3 (최근 30일)
Brian Mabe
Brian Mabe 2017년 6월 5일
댓글: dpb 2017년 6월 5일
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에서 Descriptive Statistics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by