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 />

[newdata,name] = deal(TEST{1:2})<br />

Thisexampleshowshowtoaccessthefirstandsecondelementsofthe<br />

structure TEST:<br />

newdata = TEST.measure<br />

name = TEST.name<br />

The varargin and varargout arguments are examples of the utility of cell<br />

arrays as substitutes for comma-separated lists. Create a 3-by-3 numeric<br />

array A:<br />

A = [0 1 2; 4 0 7; 3 1 2];<br />

Now apply the normest (2-norm estimate) function to A, andassignthe<br />

function output to individual cells of B:<br />

[B{1:2}] = normest(A)<br />

B =<br />

[8.8826] [4]<br />

All of the output values from the function are stored in separate cells of B.<br />

B(1) contains the norm estimate; B(2) contains the iteration count.<br />

NestingCellArrays<br />

A cell can contain another cell array, or even an array of cell arrays. (Cells<br />

that contain noncell data are called leaf cells.) You can use nested curly<br />

braces, the cell function, or direct assignment statements to create nested<br />

cell arrays. You can then access and manipulate individual cells, subarrays of<br />

cells, or cell elements.<br />

Building Nested Arrays with Nested Curly Braces<br />

You can nest pairs of curly braces to create a nested cell array. For example,<br />

clear A<br />

A(1,1) = {magic(5)};<br />

A(1,2) = {{[5 2 8; 7 3 0; 6 7 3] 'Test 1'; [2-4i 5+7i] {17 []}}}<br />

A =<br />

2-111

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

Saved successfully!

Ooh no, something went wrong!