Thursday, October 25, 2012

Pearls of Latex and Matlab

1.1 Insert a graph
\usepackage{graphicx}

\begin{figure}[tbp]
\centering
\includegraphics{psu.jpg}
\caption{Including an external graphics file with...}
\end{figure}

1.2 List
\begin{itemize}
\item First Item
\item Second Item.
\item Third item.
\end{itemize}

\begin{enumerate}
\item First Item
\item Second Item.
\item Third item. \bf{Different} labels here.
        \begin{enumerate}
        \item First nested item
        \item Second item.
        \end{enumerate}
\end{enumerate}

1.3 Font
Bold Font
\\        %line break
{\bf This is a test}
\textbf{This is a test}
\textsc{This is a test}        %small capital letter
\emph{Emphasize part here}
footnote \footnote{A foot note}        %footnote format


Matlab

whos   and who       % show variables
load file.m              % load m file
vps(pi, 300)                         Display the first 300 digits of pi
p = 'hello world'
x = input('Accept a number: ')   % default is number
y = input('Accept a string', 's')   % accept a string
x = double(char('9'))                 % the ASCII number of '9'


>> for i='a':'z'        % demonstrate the for loop and type cast
double(char(i))
end


A=[1 2 3 4 5]                      Vector
size(A)            1x5
length(A)         length of A
A(3)                the third item of array
disp(A(3))       display the third item of array

A=[1,2,3; 4,5,6; 7,8,9]        Define a matrix
A=[A;[1 2 3]], [1;2;3;4]];    semicolon at the end of the statement suppresses the display of such a matrix.The size of a matrix can be expanded or reduced dynamically.

zeros(4)                  zero matrix square with 4*4
magic(4)                 magic matrix square with 4*4
rand(4)                   4*4 matrix with rand values
randsrc(m,n)           generate a matrix which elements are 1 or -1 with probability
b = A(:,[3])            get the first and last column
c = A(2,:)               get the first row
A'                          Transpose matrix
c = [A;B]               vertically concatenation
c = [A B]               horizontally concatenates
size(A)                   size of a matrix
A = ones(8,7)
A = reshape(A, 14, 4)    The number of elements must be equal

A(2:3,2:3)              2,3 row and 2,3 column
A(1:2:end,:)            get the odd row
A(:,1:2:end)            get the even column
v=[1 2 3]               
A=ones(3,1000)
>> for i=1:1000
A(:,i)=v                  for colume fill
end

>> linspace(F,L,N)    % F start point; L End point; N segments
>> v=F:G:L              % F start point; step size G; L End point

>> x=[1,2,3,4]; y=[1,3,3,0]
>> plot(x,y)
>> axis('equal')      % will use the same scaler on both x-coo and y-coo
>> xlable('x')      
>> ylable('y')
>> title('Title part')
>> hold on            % add more graphs until hold off

No comments:

Post a Comment