Sunday, January 31, 2010

switch, otherwise, disp

more things i should've known and/or always forget:

switch is supposed to be better than a list of if, elseifs. i can think of some cases where i should've used this.

a very clear and not flashy 3 minute video explaining this:
http://blogs.mathworks.com/videos/2008/01/02/matlab-basics-switch-case-vs-if-elseif/

otherwise is the default value of switch (also explained in video)

the video shows the use of disp, which is a very simple command to display text that i have forgotten in the past and spent a long time trying to remember. it is particularly good if you want to print things out to the screen to know how your program is running (e.g. error messages, transient values, loop number, etc.).

disp('SIGH');

Saturday, January 30, 2010

text as TeX or un-TeX

continuing the tradition of writing about stuff that i haven't really implemented in the past...

text properties

important: the default is to interpret strings as TEX instructions, and that is why the underscores in my titles always mess it up by creating subscripts. i need to set the text interpreter to none. then i need to be cool and start having some LaTeX equations in my other plots.

from the Text Properties page:

Interpreter
latex | {tex} | none

Interpret TEX instructions. This property controls whether MATLAB interprets certain characters in the String property as TEX instructions (default) or displays all characters literally. The options are:

latex — Supports a basic subset of the LATEX markup language.

tex — Supports a subset of plain TEX markup language. See the String property for a list of supported TEX instructions.

none — Displays literal characters.

Latex Interpreter

To enable the LaTEX interpreter for text objects, set the Interpreter property to latex. For example, the following statement displays an equation in a figure at the point [.5 .5], and enlarges the font to 16 points.

text('Interpreter','latex',...
'String','$$\int_0^x\!\int_y dF(u,v)$$',...
'Position',[.5 .5],...
'FontSize',16)



Wednesday, January 27, 2010

setting defaults: startup.m

this might have been useful to learn 7 years ago: make a startup.m file and put it in your path, you can set all sorts of defaults like line widths, colors, etc.

http://www.mathworks.com/support/tech-notes/1200/1205.html

see:
Section 5: Setting default property values

If I ever get around to it I'll set font to Arial, size to 14, LineWidth to 2. Or something like that.

Tuesday, January 26, 2010

octave: matlab's cousin

since we all like free things, and open source, here is the link to matlab's cousin, octave:

http://www.gnu.org/software/octave/

i've never used it, but i'd feel like a stud if i knew how.

GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.

...There were still some people who said that we should just be using Fortran instead, because it is the computer language of engineering [if you were born in the 1800s], but every time we had tried that, the students spent far too much time trying to figure out why their Fortran code failed and not enough time learning about chemical engineering. We believed that with an interactive environment like Octave, most students would be able to pick up the basics quickly, and begin using it confidently in just a few hours.

***

Somebody needs to kill FORTRAN, okay? I guess if I actually knew that language, I could help the world be free of it. But I don't, I just like to make disparaging remarks about it. In ~10 years I'm going to be one of those old folks who still tries to hold on to the technology/software/languarges that I learned in my youth. I already feel sorry for myself now.

Monday, January 25, 2010

anti-illustrator

adobe illustrator has its purposes, but let those purposes NOT be to tweak matlab output so that it looks more aesthetically pleasing.  matlab output edited by illustrator one time is tolerable, but if you have to do it two, three, four times before you get your final plot, you're likely to poke your eyes out with a blunt object.

don't be a fool!

not that i've mastered these commands yet, but setting font, font size, line width, and tick properties goes a LONG way. i haven't used illustrator to "fix" a plot since i've started using stuff like this:

xlb=xlabel('strength (kPa)','FontName','arial');
ylb=ylabel('erosion','FontName','arial');

set([xlb ylb],'FontSize',14,'FontName','arial','LineWidth',1.5 )

axis square;

set(gca,'FontSize',14,'FontName','arial', 'LineWidth',1.5, 'Ticklength', [0.025 0.025])

gca is important.

Friday, January 22, 2010

axis of evil

i love me some square axes:

axis square;

i am also always setting axes bounds:

axis([xmin xmax ymin ymax]);

but there are tons of other axis options i have not checked out fully.

axis 'auto yz';

axis auto
axis manual
axis tight
axis fill
axis ij
axis xy
axis equal
axis image 
axis square
axis vis3d
axis normal
axis off
axis on


aesthetics people, aesthetics...

and another reason that matlab beats the pants off of excel.

Thursday, January 21, 2010

colors

colors are important if you want your MATLAB plots to be aesthetically pleasing. which you should. because it makes life more enjoyable. i mean, see how the colors of the header image and the titles and links sort of match each other on this page, that is NOT by accident. and it pleases me.

another advantage of specifying your own colors is that you can make a bunch of personal colors that convert to the correct gray-shade. that way you can make one set of images for presentations (colorful!) and easily convert it to grey shade for papers. ingenious!

here's a webpage with the RGB codes for many colors:
http://en.wikipedia.org/wiki/Web_colors

in matlab colors are specified with RGB values between 0 and 1, not 0 and 255. so simply specify the code given on that page, e.g. i,j,k, like so: [i/255 j/255 k/255]

example:
plot(.6,1.5,'o', 'MarkerEdgeColor', [0 0 0], 'MarkerFaceColor', [70/255 130/255 180/255], 'MarkerSize',11, 'LineWidth', 1.5);

steel blue, mmmmmm.

btw, "coulours" is one of my favorite songs by The Prodigy.