Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

This is in matlab.

OpenStudy (espex):

A for loop is going to run for a certain amount of time, what are your conditions?

OpenStudy (espex):

You might just put an if statement in to do what you want.

OpenStudy (anonymous):

i meant an if statement

OpenStudy (anonymous):

Sorry about the confusion.

OpenStudy (anonymous):

is there such thing as an if loop?

OpenStudy (espex):

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.

OpenStudy (espex):

You want something like this? if tone_end_found == 1 indx = indx+1; elseif tone_end_found == 0 indx = indx + (5*Fs); end

OpenStudy (anonymous):

yes.

OpenStudy (espex):

Kewl, well there ya go. :)

OpenStudy (anonymous):

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

OpenStudy (anonymous):

Starting around line 7 from the bottom.

OpenStudy (anonymous):

I think it's good. Thank you!!

OpenStudy (espex):

You're welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!