How to write a for loop for the following window: while (indx(end) <= numel(d)) && (tone_end_flag == 0)% index is the window that scans ands stops before d ends x = d(indx); [freqX magX] = goertz_max(x,Fs,20,22); if magX>1e7 && tone_flag == 0 tone_flag = 1; maxX = magX; elseif magX>maxX maxX = magX; end if (tone_flag == 1) && (magX < maxX/2) tone_end_flag = 1; tone_end = indx(1); end A = [A magX]; indx = indx + 1; end
The second to last line, ind=ind+1, I need to change it into a for loop that will do the following: Add 1 to indx if tone_end_found is 1 Add 5*Fs to indx if tone_end_found is 0.
This is in matlab.
A for loop is going to run for a certain amount of time, what are your conditions?
You might just put an if statement in to do what you want.
i meant an if statement
Sorry about the confusion.
is there such thing as an if loop?
No, it is a simple statement, if you want something to run but you don't know how long, you can usually put it into a while loop.
You want something like this? if tone_end_found == 1 indx = indx+1; elseif tone_end_found == 0 indx = indx + (5*Fs); end
yes.
Kewl, well there ya go. :)
If I was to write it into this part of the code, will it be incorrect? x = d(indx); [freqX magX] = goertz_max(x,Fs,20,22); if magX>1e7 && tone_flag == 0 tone_flag = 1; maxX = magX; elseif magX>maxX maxX = magX; end if (tone_flag == 1) && (magX < maxX/2) tone_end_flag = 1; tone_end = indx(1); end A = [A magX]; indx = indx + 1; if tone_end_found == 1 indx = indx+1; elseif tone_end_found == 0 indx = indx + (5*Fs); end end
Starting around line 7 from the bottom.
I think it's good. Thank you!!
You're welcome.
Join our real-time social learning platform and learn together with your friends!