How do I find peak duration with the following scatterplot?
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
dpb
on 5 Jun 2017
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 Comments
dpb
on 5 Jun 2017
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
on 5 Jun 2017
"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???
More Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!