You are on page 1of 4

Key: i=numbei of iows c=numbei of columns

Cieating a vectoi: A= |,,,,j Filling a vectoi with zeios A=zeios(i,c)


Cieating a vectoi full of evenly spaceu values: C=linspace(low, hi, numvalues)
To iemove a vectoi element: A(inuex)=|j iemoves the element at inuex
Rounu(v) uses (conventional) iounuing,
ceil(v) iounus up to the next integei
flooi(v)iounus uown to the next integei
fix(v) iounus in the uiiection of zeio (uown foi +, up foi -)
stait : inciement : enu
Aiiays: A| iow, columnj
Ranu(iow, column) fiom zeio to one
Length(a) ueteimines the laigest uimension of an aiiay
Size(a) ietuins (iows, columns)
Chai() ans=u
Bouble('fieu') ans = ( )
Ischai(a) ietuins tiue if a is a chaiactei stiing
Sticmp(s,s) compaies two stiings, ietuins tiue if they aie the same
A{}= A=|j
B|j= {| j}; B= |x uoublej
uetfielu(sti,<flu>) extiacts the value of the fielu <flu>
Stiuct(.) constiucts a stiuctuie fiom <fieluname> anu <value> paiis of paiameteis
Xlswiite(file, uata, sheet, iange) wiites to an excel spieausheet with given paiams
Fh=fopen (file, fl) opens a text file foi ieauing oi wiiting
Fgets(fh) ieaus a line incluuing the new line chaiactei
Plotting
* plot(x,y) plots x veisus y on a giaph
* giiu on shows a giiu on the plot, giiu off iemoves giiu lines
* holu on leaves eveiything on the plot, holu off eiases eveiything pievious
*(axis)label(.) sets the . as the label foi the axis wheie (axis) is the vaiiable
ueLermlne Lhe Lype (class) of each of Lhese varlables
a ^= : 0oub1e
b 8=j2 : 0oub1e
c C={2) : Ce11
d 0 = C{) : Ce11
e L = C{) : 0oub1e
f C{) = '^8C', I = C{) : Ce11
g 6 = C{) : Char
h u = c1ass{6) : Char
l 1 = c1ass{u) : Char

Load (read) a 3llne flle uslng a for loop sLore ln a column vecLor
1uncton Co1vec = 1oadI1e
nputI1e = 1open{'data.txt'),
1or =:S
1ne = 1get1{nputI1e),
Co1vec{,) = 1ne,
end
1c1ose{nputI1e),
end

Load 3llne flle uslng a whlle loop sLore ln a column vecLor
1uncton Co1vec = 1oadI1e
nputI1e = 1open{'data.txt'),
Co1vec = {),
wh1e ~1eo1{nputI1e)
1ne = 1get1{nputI1e),
Co1vec{end+,) = 1ne,
end
1c1ose{nputI1e),
end

Load array from dlsk
1uncton ^rray = 1oad^rray{11euame)
nputI1e = 1open{11euame),
n8ows = strdoub1e{1get1{nputI1e)),
nCo1s = strdoub1e{1get1{nputI1e)),
1or row=:n8ows
1or co1=:nCo1s
^rray{row,co1) = strdoub1e{1get1{nputI1e)),
end
end
end






ave array Lo dlsk
1uncton save^rray{^rray, 11euame)
jn8ows nCo1s = sze{^rray),
outputI1e = 1open{11euame, 'w'),
1prnt1{outputI1e, 'xd\nxd\n', n8ows, nCo1s),
1or row=:n8ows
1or co1=:nCo1s
1prnt1{outputI1e, 'xd\n', ^rray{row, co1)),
1prnt1{outputI1e, 'xd\n', ^rray{row, co1)),
end
end
1c1ose{outputI1e),
end

roL13
1uncton s = rot2{s)
s= '',
1or c-s
1 c>= '^' && c <= 'M'
c=char{c + 2),
e1se
c=cahr {c-2),
end
s{end+)=c,
end
end

CounL leLLers
1uncton Counts = countletters{ strng )
d11 = 'a' - '^',
Counts = zeros{, 6),
1or 1etter = strng
1 1etter >= 'a' && 1etter <= 'z'
1etter = 1etter - d11,
e1se
1etter = 1etter,
end
1 1etter >= '^' && 1etter <= '2'
ndex = 1etter - '^' + ,
Counts{ndex) = Counts{ndex) + ,
Lnd
Lnd
Lnd


1uncton S = 1ettersStruct{^rray)
1or =:S
S.{char{'^'+)) = ^rray{+),
end
end
ConverL cell array Lo sLrucLure
1uncton S = castruct{C^)
n8ows = sze{C^, ),
1or =:n8ows
name = C^{,),
va1ue = C^{,),
S.{name) = va1ue,
end
end

Convert structure to ce11 array
1uncton C^ = structca{S)
names = 1e1dnames{S),
row = ,
1or name = names'
name = name{),
C^{row, ) = name,
C^{row, ) = S.{name),
row = row + ,
end
end

You might also like