Automatically plot different colored lines

You could use a colormap such as HSV to generate a set of colors. For example: cc=hsv(12); figure; hold on; for i=1:12 plot([0 1],[0 i],’color’,cc(i,:)); end MATLAB has 13 different named colormaps (‘doc colormap’ lists them all). Another option for plotting lines in different colors is to use the LineStyleOrder property; see Defining the Color … Read more

Using i and j as variables in MATLAB

Because i and j are both functions denoting the imaginary unit: http://www.mathworks.co.uk/help/matlab/ref/i.html http://www.mathworks.co.uk/help/matlab/ref/j.html So a variable called i or j will override them, potentially silently breaking code that does complex maths. Possible solutions include using ii and jj as loop variables instead, or using 1i whenever i is required to represent the imaginary unit.

Is there a foreach in MATLAB? If so, how does it behave if the underlying data changes?

MATLAB’s FOR loop is static in nature; you cannot modify the loop variable between iterations, unlike the for(initialization;condition;increment) loop structure in other languages. This means that the following code always prints 1, 2, 3, 4, 5 regardless of the value of B. A = 1:5; for i = A A = B; disp(i); end If … Read more

Is it possible to define more than one function per file in MATLAB, and access them from outside that file?

The first function in an m-file (i.e. the main function), is invoked when that m-file is called. It is not required that the main function have the same name as the m-file, but for clarity it should. When the function and file name differ, the file name must be used to call the main function. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)