%----------------------------------------------------------------- % % Script with basic examples of using cells and structs in Matlab. % One point is that cells are defined/indexed using {} instead % of (), and that what you get back is a cell, not the contents of % the cell. Also, structs can be considered as heterogenous arrays % versus the usual Matlab arrays, which require every element in % them to be of the same type. % %----------------------------------------------------------------- echo on; A= {rand(2,2,2), ' February', 10.28} pause; whos pause t = A(1,3) pause whos %------------------------------------------------------------ % Next statement was commented out because it made the script % barf and stop at this point. Uncomment it to see what the % problem/err message is. %------------------------------------------------------------ % u = t/2 pause t = A{1,3} pause u = t/2 pause A{1,1}(2,:,1) pause B{1,1}=1:8; pause B{1,2}=strvcat('Monday','Tuesday','Wednesday','Thursday'); pause B{2,2}=A; pause B{1,1} pause A{1,1}(2,:,1) pause % Nifty function to see what's what cellplot(B) pause %------------------------------------------------------------------- % Next two show that when building a struct, every field in it must % either have one value or n values, but you cannot have some fields % with different (but larger than 1) sizes. %------------------------------------------------------------------- s = struct('name',{'fred','ethel','georgina','anon'},'state','Iowa','weight',{133 416 200 177}) whos pause another_s = struct('name',{'fred','ethel','georgina','anon'},'state','Iowa','weight',{133 200 177}) pause