E7_lecture05 - 'N2' 0.01 'argon' 40 'Ar' }...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
E7, Fall 2008, Lecture 5 ell Arrays Cell Arrays Structure Arrays 1 a r r a y 1 32 25 98 4 number array a r r a y H E L O L character array aa a ay 2 a r r a y length( ) a r r a y sum( ) isempty( ) a r r a y 3 Example: Molecular Weight of Air AIR is a mixture of 21 % Oxygen (W = 32) 78 % Nitrogen (W = 28) Argon (W = 40) 1 % Argon (W 40) W * X W * W * X W air = W O 2 X O 2 + W N 2 X N 2 + W N 2 X N 2 2 * 21 8 * 78 0 * 01 = 32 0.21 + 28 0.78 + 40 0.01 4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MATLAB W air = W O 2 * X O 2 + W N 2 * X N 2 + W N 2 * X N 2 = 32 * 0.21 + 28 * 0.78 + 40 * 0.01 >> w =[32 28 40]; > [ 21078001 ; >> x =[0.21 0.78 0.01]; > sum( * >> sum( w . x ) > dot( >> dot(w,x) 5 Matlab Cell Arrays >> air = { 0.21 'oxygen' 32 'O2' 0.78 'nitrogen' 28 'N2' 0.01 'argon' 40 'Ar' } >> air{1,3} >> air(1,3) 6 Matlab Cell Arrays >> air = cell(3,4) >> air{1,1} = 0.21 >> air{1,2} = 'oxygen' 7 Matlab Cell Arrays >> air = { 0.21 'oxygen' 32 'O2' 0.78 'nitrogen' 28
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 'N2' 0.01 'argon' 40 'Ar' } >> O2 = air(1,:) >> w = [air{:,3}] >> molW = dot( w, [air{:,1}] ) 8 Matlab Cell Arrays >> air = { 0.21 'oxygen' 32 'O2' 78 ' itrogen' 8 ' 2' 0.78 nitrogen 28 N2 0.01 'argon' 40 'Ar' } >> size(air) >> sortrows(air,3) >> cellplot(air) >> celldisp(air) 9 STRUCTURE ARRAY: molecule olecule ame = ' xygen' molecule.name = oxygen ; molecule.formula = 'O2'; molecule.mass = 32; molecule(2).name = 'nitrogen'; olecule formula = ' 2' molecule(2).formula = N2 ; molecule(2).mass = 28; 10 STRUCTURE ARRAY: molecule >> molecule(2).name >> molecule(2).mass >> [molecule( : ).mass] 11 STRUCTURE ARRAY: molecule >> length(molecule) >> size(molecule) >> fieldnames(molecule) 12...
View Full Document

Page1 / 3

E7_lecture05 - 'N2' 0.01 'argon' 40 'Ar' }...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online