In an assignment A(I) = B, the number of elements in B and I must be the same.

I'm not quite sure what is wrong with my code. I am trying to figure out a ranges from my y-axis to determine what to name certain peaks: For example, if the peaks lie within the range of 0.1-0.3, the are considered "twave", from 0.3-0.6 they are "rwave", and from 0.6 - 1 they are "wave".
Does anyone have any advice?
"equalize" is the file that I am reading
function [ pwave,rwave,twave ] = peakwaves( equalize )
peakwaves = findpeaks(equalize, 'MINPEAKHEIGHT',0.1); %configures all of the peaks
a = length(peakwaves);
counter1 = 0;
counter2 = 0;
counter3 = 0;
for i = 0.1:a;
if 0.3 < a && a < 0.6;
counter = counter + 1;
pwave(counter) = peaks(i);
elseif .1 < a && a < 2.9;
counter2 = counter2 + 1;
twave(counter2) = peaks(i);
else a < 1;
counter3 = counter3 + 1;
rwave(counter3) = peaks(i);
end
end

Answers (1)

When you wrote pwave(counter) = peaks(i); , peaks is not defined
Also a = length(peakwaves); is an integer, What [0.3, a] represent?
Try this
function [ pwave,rwave,twave ] = peakwaves( equalize )
peakwaves = findpeaks(equalize, 'MINPEAKHEIGHT',0.1);
pwave = peakwaves(0.3 < peakwaves & peakwaves < 0.6);
rwave = peakwaves(0.6 <= peakwaves & peakwaves < 1);
twave = peakwaves(1 <= peakwaves & peakwaves < 2.9);

12 Comments

Like I said, I'm trying to defined the peaks by ranges. Do you suggest a better way of doing this?
the 0.3 < a && a < 0.6 means that if the peak (meaning a) falls within that range, then it outputs pwaves. Does this make sense?
And i need to keep each pwave peak separate for later diagnosis.
so, if you see the picture....
the waves repeating in the range from:
0.1-0.2 are "pwave"
0.8 - 1 are "rwave"
0.3-0.6 are "twave"
Ok, have you read all my answer?
i just did.... the error looked like this:
Operands to the and && operators must be convertible to logical scalar values.
Sorry, I copied and pasted a part of your code, use & instead of &&
pwave = peakwaves(0.3 < peakwaves & peakwaves < 0.6);
rwave = peakwaves(0.6 <= peakwaves & peakwaves < 1);
twave = peakwaves(1 <= peakwaves & peakwaves < 2.9);
will this allow me to use all of the waves considered "pwave" and ect?
that just gives me the peak values. does nothing to store them within their range.
I have just corrected your code. There is no indices stored in your code.
idx_pwave= find(0.3 < peakwaves & peakwaves < 0.6);
pwave = peakwaves(idx_pwave)
idx_rwave=find(0.6 <= peakwaves & peakwaves < 1);
rwave = peakwaves(idx_rwave);
idx_twave=find(1 <= peakwaves & peakwaves < 2.9);
twave = peakwaves(idx_twave);
if i was trying to do this using a logical by storing all of the peaks, and then falsifying the other peaks for isolation, how would i do that?
"Falsifying other peaks" What do you mean?
meaning, I can load all peaks in the file from 0.1 to 1
consider "rwaves" = 0.6 to 1
and consider "twaves" to be 0.3 to 1 false if rwaves
and consider "pwaves" to be 0.1 to 1 false if twaves
so they continue to cancel out the previous condition as the scale increases

This question is closed.

Products

Asked:

on 6 Nov 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!