MEAM.Design - Matlab - Random Tips

help ____ - if you don't know how to use a command, type "help" followed by that command, and Matlab will spit out just about everything that it knows. If that isn't enough, check the help browser built into Matlab for even more information.

lookfor _____ - if you can't remember the name of a command, but know something of what it does, you can use lookfor to search through the help files.

clear - clear all variables from memory (a very good idea at the start of a script). Note that this does not remove global variables (use clear global for this).

you should define constants at the top of your scripts - that way you don't have to go fishing for them later!

use the percent sign (%) to start a comment

disp() - display something to the command prompt

you cannot access function variables from the workspace

F5 - use it!

why - just try it.

everything in Matlab starts with 1!

Control-C - that's how to force Matlab to stop doing something. Really useful when you're stuck in an infinite loop!

247 Electronics lab specific:

pause(n) - pauses your code for n seconds, where you can use values as small as 0.01 with decent results.

length(a) - returns the length of a 1-d vector

for(i=1:length(a))

C = [A B] - concatenate two 1-d row vectors together (can also be used as A = [A B] to add B to the end of A)

C = [A; B] - concatenate two 1-d column vectors together

string = input('promptText','s') - put the promptText on the command line and wait for a string of text to be input, ending with the Enter key. \n can be used in the promptText to create a new line.

Other:

[X, map] = imread(...) - reads an image file into X and its colormap into map

image(X) - displays a graphical image with color (or brightness) from the elements of the matrix X [Image(X) can be used to display an image that has been read using imread(...) ]

tic - starts a stopwatch timer. toc - prints the elapsed time since tic was executed. This can be used to precisely time the duration of a function, script, or segment of code within a function/script.

num2str(A) - converts a number, A, to its string representation

strcat(s1, s2, s3, ...) - horizontally concatenates strings containing equal numbers of rows

get/set, get the x-data, y-data, change that, rather than replotting