How can I find the troughs of something without using the function findpeaks?
%This function is meant to help me find the troughs of the flow plot but I keep getting values that almost work but don’t work, I was told by a classmate that to find the troughs I need to find the beaks then work backwards
function [troughs] = findTroughs(flowData)
flow = flowData(:,2);
t = flowData(:,1);
troughs = [];
for i = 3:length(flow)-2
if flow(i) < flow(i-1) && flow(i) < flow(i-2) && flow(i) < flow(i+1) && flow(i) < flow(i+2)
isAbsolute = true;
for j = (i-10):(i+10)
if j>=1 && j<=length(flow) && flow(i)>flow(j)
isAbsolute = false;
break
end
end
if isAbsolute && ~any(troughs == i) % Check if trough index already exists
troughs = [troughs, i];
end
end
end
end%This function is meant to help me find the troughs of the flow plot but I keep getting values that almost work but don’t work, I was told by a classmate that to find the troughs I need to find the beaks then work backwards
function [troughs] = findTroughs(flowData)
flow = flowData(:,2);
t = flowData(:,1);
troughs = [];
for i = 3:length(flow)-2
if flow(i) < flow(i-1) && flow(i) < flow(i-2) && flow(i) < flow(i+1) && flow(i) < flow(i+2)
isAbsolute = true;
for j = (i-10):(i+10)
if j>=1 && j<=length(flow) && flow(i)>flow(j)
isAbsolute = false;
break
end
end
if isAbsolute && ~any(troughs == i) % Check if trough index already exists
troughs = [troughs, i];
end
end
end
end %This function is meant to help me find the troughs of the flow plot but I keep getting values that almost work but don’t work, I was told by a classmate that to find the troughs I need to find the beaks then work backwards
function [troughs] = findTroughs(flowData)
flow = flowData(:,2);
t = flowData(:,1);
troughs = [];
for i = 3:length(flow)-2
if flow(i) < flow(i-1) && flow(i) < flow(i-2) && flow(i) < flow(i+1) && flow(i) < flow(i+2)
isAbsolute = true;
for j = (i-10):(i+10)
if j>=1 && j<=length(flow) && flow(i)>flow(j)
isAbsolute = false;
break
end
end
if isAbsolute && ~any(troughs == i) % Check if trough index already exists
troughs = [troughs, i];
end
end
end
end plotting, subplot MATLAB Answers — New Questions