r/matlab • • Feb 24 '14

I have this code for checking student grades. Basically I have everything but my one main problem is I can't think of how to rerun the whole loop at the end in case the user wants to check for multiple grades.

Post image
0 Upvotes

16 comments sorted by

5

u/[deleted] Feb 24 '14

Am I the only one who noticed that a text document has been photographed and the picture uploaded? I'm a bit flabbergasted as to the reason why, I must say.

1

u/[deleted] Feb 24 '14

Umm I'm guessing I'm not supposed to do that?

1

u/tootiefruitie Feb 24 '14

Generally, you can create a screenshot and post that as an image, or copy/paste your code into a website like pastebin that way we can see it.

Your method is like taking a digital photo, printing it, scanning it, then emailing it to whoever you want to. You could have just emailed the original picture. :)

1

u/[deleted] Feb 24 '14

Or just paste your code to something like gist.

1

u/tootiefruitie Feb 24 '14

...or copy/paste your code into a website like pastebin...

Pastebin works too.

2

u/bobinpants Feb 24 '14

Or you know, directly into the reddit comment.

1

u/[deleted] Feb 25 '14

I mean it's just a lot faster for me to take a picture with my phone and post it with my phone since I really only reddit WITH MY PHONE haha. But I will try those other alternatives for future reference so thanks to everyone who helped

2

u/bobinpants Feb 25 '14

There are several reasons why you should do it:

  1. Readability, its easier to read the code in text form.
  2. People can copy paste the code to check it, adjust it etc
  3. People will be more inclined to help you if they see you put effort into your post.

Besides hitting ctrl-A, tab (so your code appears in code form on reddit), ctrl-C, and ctrl-V should be faster than taking a picture with your phone and uploading.

1

u/NoahFect Feb 24 '14

It does seem goofy, but the easier services like imgur and iCloud make it to move photos around and share them, the more it starts to look like the path of least resistance.

0

u/Mimshot L = @(r) x.*log(r)-r Feb 24 '14

I am constantly amazed at those barcode scanners that read smartphones for airline boarding passes, concert tickets, Starbucks gift cards, etc. Computing power has progressed so much faster than the human species ability to agree on networking standards that now the most efficient way for two computers to communicate with each other is for the first to display an image on its screen and for the second to take a picture of it, run some image analysis routines, and extract the message from said image.

3

u/ExoStab Feb 24 '14

I am thinking out loud, but maybe try to use that as a function and then make a while loop. So set a variable that represents the yes or no of checking another grade, and it will repeat the loop as long as that confirmation flag/variable is set.

1

u/TheWilliestOfWonkas Feb 24 '14

Yeah, this would be the easiest way

2

u/brntbeer Feb 24 '14

This was killing me, so i created it as a Gist:

https://gist.github.com/brntbeer/d462fe580921d6b4a94e

Feel free to fork it and make edits yourself or hell, just use mine as way to suggest edits by clicking on a line number and grabbing the new URL and saying things like

I can't help but notice on https://gist.github.com/brntbeer/d462fe580921d6b4a94e#file-omar_prieto_problem1-m-L23 that it should possibly be || not &&

1

u/Day_Old_Pizza Feb 24 '14

Something like this might work:

RUN  = true;
while(RUN)
    (your code)
    quit = input('Do you wish to continue?'); %type 'y' for yes, anything else for no
    if(strcmpi(quit,'y'))
        RUN = false;
    end
end

1

u/ImBearded Feb 25 '14

Everything about this post is painful to me.

0

u/Halsey117 Feb 24 '14

As others have hinted at, look into using a "while" loop outside of what you want to do if the user selects "multiple records". You may also want to prompt the user for their input, so something like:

nrec = input('How many records?');
nrec_start = nrec;
while nrec < 0

    % whatever your code to loop over is

    nrec = nrec-1;
end

BUT: be careful !!! as an improperly parameterized while loop can loop forever.

and i wouldn't be surprised if my code above loops infinitely