Monthly Archives: February 2011

<code>M = rand(10,2);
x = 1:size(M,1);
plot(x, M(:,1), 'b.-', x, M(:,2), 'g.-')
legend('M1', 'M2')
for i=x
    text(i+0.1, M(i,1), sprintf('%.2f', M(i,1)), 'fontsize',7, 'color','b' );
    text(i+0.1, M(i,2), sprintf('%.2f', M(i,2)), 'fontsize',7, 'color','g' );
end
</code>

alt text

Alternatively, you can use:

<code>datacursormode()
</code>

which will enable the user to just point and click on points to see the data label.

You can label each axis with the function:

<code>xlabel('label')
ylabel('label')
</code>

These can also take cell arguments, where each row is a new line. That’s handy for showing units. Labeling each point on the figure can be done as so:

<code>for i=1:length(M)
    text(M(i,1),M(i,2),'Label Text')
end
</code>

The label text can also be a string variable that you can edit with sprintf and make special strings for each point.

Matlab multi line plot in the same window.

There are two common ways to plot more than 2 data on the same window.

The first method uses one line and is of the form plot(xfunction, style#1 ,x, function#2style#2, ). For example,

plot(x,x.^2,’-ro’,x,x.^3,':bo’)
The second method involves the use of the “hold on” and “hold off” commands. After creating the first graph, use the “hold on” command, forcing subsequent graphing commands to be placed in the same window. Now type in your second plot command. When you are through, type “hold off”. For example

plot(x,x.^2,’–ro’)
hold on
plot(x,x.^3,’-bd’)
plot(x,-x,’g+’)

To add labels to your axes, use the following

xlabel(‘this goes across’)
ylabel(‘this goes up)
hold off

Latex: Numbered Subsubsections

LaTex lets you break the document down into chapters, sections, subsections, subsubsections and paragraphs. By default subsubsections and paragraphs are not numbered or included in the table of contents. Sometimes this might be desirable. However, I usually find that in cases when I do not need them numbered, I usually never use them (ie. my documents are broken down by chapter, section, and subsection only). At other times, when I desire more granularity, I actually want subsubsections to show up in the TOC and have distinctive headings and numbers.

To enable this you will need to put 2 lines of code somewhere in your preamble:

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

The first line enables numbering of subsubsections. The second line includes subsubsections in the table of contents.

Btw, if you need to break down your document even more you can switch 3 to 4 in these lines to enable numbering for paragraphs.