23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Cell Arrays<br />

For example, array A has three levels of nesting:<br />

• To access the 5-by-5 array in cell (1,1), useA{1,1}.<br />

• To access the 3-by-3 array in position (1,1) of cell (1,2), useA{1,2}{1,1}.<br />

• To access the 2-by-2 cell array in cell (1,2), useA{1,2}.<br />

• To access the empty cell in position (2,2) of cell (1,2), use<br />

A{1,2}{2,2}{1,2}.<br />

Converting Between Cell and Numeric Arrays<br />

Use for loops to convert between cell and numeric formats. For example,<br />

create a cell array F:<br />

F{1,1} = [1 2; 3 4];<br />

F{1,2} = [-1 0; 0 1];<br />

F{2,1} = [7 8; 4 1];<br />

F{2,2} = [4i 3+2i; 1-8i 5];<br />

Now use three for loops to copy the contents of F into a numeric array NUM:<br />

for k = 1:4<br />

for m = 1:2<br />

for n = 1:2<br />

NUM(m,n,k) = F{k}(m,n);<br />

end<br />

end<br />

end<br />

Similarly, you must use for loops to assign each value of a numeric array to<br />

a single cell of a cell array:<br />

2-113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!