The Lansey Brothers" Blog

Sunday, July 12, 2009

Fun with Matlab, why

Lately I've been running a few Matlab programs that take about 5 minutes to finish. Naturally I continue to use my computer - but then I don't know when its finished. To solve this problem I add a bit of code to the end of all my programs which will play a sound - like the beep of a microwave, or the ding of a toaster to let me know that my numbers are fully crunched.

If you would also like to have this for your own programs just slip the following into the end.

%% To play a sound
T=419*2; T2=419*4; st=[1:.3:T]; t2=[1:.3:T2];
S=(sin(t*pi/T).^.2+sin(t*pi/T).^2).*sin((t+sin(t/2)*.2).^1.0)/2;
S2=(sin(t2*pi/T2).^.4+sin(t2*pi/T2).^4).*sin((t2+sin(t2/2)*.2)*1.5)/2;
sound([S S],8192); sound(S2,8192);

Another great thing to do in Matlab: type "why" into the command line (without quotes) and see what it answers. Just the word 'why'. Now I would love to show you an example (they are quite funny) but the computer I'm using doesn't have Matalb. The person who posts a comment with the longest answer that matlab gives to that question wins.

8 comments:

Avi said...

You can also play an arbitrary .wav file using some of Matlab's built-in functions designed for that purpose. eg:

[y,Fs] = wavread(wavFilename);
playblocking(audioplayer(y, Fs));

Eli said...

The bald and not excessively bald and not excessively smart hamster obeyed a terrified and not excessively terrified hamster.

Michael Kopinsky said...

A tall and good and not excessively rich and bald and very smart and good tall and tall and terrified and rich and not very terrified and smart and tall and young hamster insisted on it.

Michael Kopinsky said...

No wait, I just got a better one.

Some very rich and tall and smart and rich and terrified and rich and very young and good and rich and very tall and tall and smart and terrified and not excessively bald and rich and smart and not very young and bald and tall and smart and terrified and rich and tall and young and bald and good and terrified system manager knew it was a good idea.

This one isn't long, but it's random:

In the beginning, God created the heavens and the earth...

Eli said...

Be sure to enter: edit why
to see the guts of the thing.

Anonymous said...

If you type why(248418) you get (MATLAB Version 7.0.1.15):
Some not excessively good and rich and rich and good and very good and rich and tall and not excessively tall and rich and good and smart and not excessively good and terrified and terrified and tall and not excessively good and not excessively young and young and terrified and smart and bald and not excessively good and good and smart and not excessively tall and bald and rich and bald and tall and rich and good and young and terrified and very young and terrified and good and not very bald and good and tall and tall and very bald and not excessively rich and bald and bald and very tall and very rich and good and very tall and good and terrified and tall and very tall and good and young and very bald and rich and good and bald and not excessively rich and bald and not very rich and tall and very smart and tall and terrified and not excessively young and not excessively tall and very bald and rich and young and tall and not very terrified and smart and rich and young and terrified and terrified and rich and smart and tall and terrified and young and rich and tall and terrified and smart engineer knew it was a good idea.

Alan WJ Selfe said...

just a guess but do you think its possible matlab was ghost programmed and its the creators way of saying screw you or is it some sort of code to be decrypted who knows

Eli said...

Alan,
You can actually see the source code for the 'why' function. I think it's kind of just a silly thing they included. If you type 'edit why' at the Matlab prompt you can see the code.