Вы находитесь на странице: 1из 6

MATLAB Ref: normrnd(mu,sigma,rows,columns) [generate a normal distribution set] range in Matlab: [1:2:10] (etc) syms a : makes a a symbolic char

double(exp) returns the numerical value magic(N) is an NxN matric with integers ranging from 1 to N^2 ind2vec to convert indices to vectors DIFFERENTIATION diff(exp,var)' INTEGRATION int('EXPRESSION','VAR',LOW_LIM,HIGH_LIM) : or declare syms variables and don't use '' DIFF EQS (http://www.math.tamu.edu/REU/comp/matode.pdf) dsolve(eqn,wrt) example: eqn='D2S+DS/s - c*S/s^2=0' dsolve(eqn,'s') pi = pi exp = e FUNCTIONS lower cased: sin(blah), tanh(blahj), etc Declare in an m-file: function [x]=scale(x,low,high, xmin, xmax)

General Notes:

help function : prints help pages num2str() : converts a number to a string concatenate strings using sq. brackets [str1,str2,str3,etc] commas separate same line statements (generally not needed) dynamically grow vectors/arrays by j(5)=blah, etc ctrl+c kills a running program period before operator with matrices means perform the operation on each element, rather than the matrix, e.g. A.^2 means square each element in A.

use pretty function to make things more readable rref does row reduced echelon form of a matrix

Loading Data: load(filename) to pull in an ascii table, canhave header lines or column names, use the internet to find these types of options More generally: A = importdata(filename, delimiter, nheaderlines) textread('FILENAME','',-1,'delimiter','\t', 'headerlines',1,'emptyvalue',NaN); BETTER TO USE TEXTSCAN fid=fopen('fileaddress') textscan(fid,'format') eg fid = fopen('data2.csv'); C = textscan(fid, '%s %n %n %n %n', 'delimiter', ',', ... 'treatAsEmpty', {'NA', 'na'}, ... 'commentStyle', '//'); use %*[^\n] to ignore rest of columns %* skips a field

General Plot: plot(blah) Plotting a polynomial: .95x^3 -5.8x^2 +10.9x -6

p= [.95 -5.9 +10.9 -6]; x= linspace(0.5,3.5); y=polyval(p,x); plot (x,y); xlabel('xtitle') plotting a equation of one variable:
t = 0:.3:10; >> y = sin(t); >> plot(t,y) gca returns the handle to the current axes of the figure gcf same but with figure gname(colmatrix_names/titles) to begin a gui that labels certain points that are plotted Arrays Use cell arrays when we don't want thigs to be the same size (ie rows or columns) C = {S1 S2 ...} (string cell array) Use the curly brace to access the content of the cell rather than the cell itself. Loops

for a=0:50 disp('Hello World') end

Side Notes: Arrays start at 1 display("blah") % prints blah to screen

(Making cdf plots on the same axis) cdfplot(x)

hold on cdfplot(y) Images use imread to read in images Statistics toolbox gplotmatrix(data) %makes all scatterplots/histograms of data PCA: Make sure to divide each var by std before using (see under other section)

Other use .op (period operator) to do something to each element of a matrix use inline to create a kronecker delta (or any quick functional formula): del=inline('n==0','n') call with del(n-j), etc... to make greek letters use \Sigma \pi, etc Can delete plots on a figure by passing the handle to the delete function: delete(h1) Divide each column of a matrix by the corresponing column in a row-matrix by using the ./ and repmat() function: h is mxn matrix cols is 1xn matrix (to divide each row) ans= h./repmat(cols,size(h,1),1) isnan() to retrieve the row numbers that contain NaNs exist(blah): checks if blah exists (e.g. a directory, file, variable, etc--returns different codes depending on what it is) o_train = [writepath ifos{inum} '_set' num2str(ii) '_training.pat']; o_test=[writepath ifos{inum} '_set' num2str(ii) '_testing.pat'];

dlmwrite(o_train, num2str(num_PC), 'delimiter', ''); dlmwrite(o_train, head_str, 'delimiter', '','-append'); dlmwrite(o_test, num2str(num_PC), 'delimiter', ''); dlmwrite(o_test, head_str, 'delimiter', '','-append'); To divide up a matrix into 10 approx equal submatrices [M,N] = size(ydata); %# Matrix size nSub = 10; %# Number of submatrices cMat = mat2cell(ydata,diff(round(linspace(0,M,nSub+1))),N); find locates non-zero elements, use with boolean comparison to extract certain rows correction, use logical indexing: A(A > 12) returns a matrix with

all elements grt 12


Think carefully whether you want to use an array of structures or a structure of arrays Structures Fill an array of structures with randn: [j(:).k] = deal([1,2,3]) Working with the OS h = unix('date') %run unix commands and return the result as a var place an exclamation point before unix commands to run them "command-line style"

SPIDER `use_spider` in intiate spider on start up

USER FUNCTIONS cullset=lowcutdata(data,coln,cutval) Neural Network Use newpnn or newlvq for classification use ind2vec to convert indices to vectors for classification purposes MEX Files

When dealing with (compiling) mex files, put them in your pwd or specify them by their entire path name...