| Programming and Data Types | ![]() |
Converting Between Cell and Numeric Arrays
Use for loops to convert between cell and numeric formats. For example, create a cell array F.
F{1,1} = [1 2; 3 4];
F{1,2} = [-1 0; 0 1];
F{2,1} = [7 8; 4 1];
F{2,2} = [4i 3+2i; 1-8i 5];
Now use three for loops to copy the contents of F into a numeric array NUM.
for k = 1:4
for i = 1:2
for j = 1:2
NUM(i,j,k) = F{k}(i,j);
end
end
end
Similarly, you must use for loops to assign each value of a numeric array to a single cell of a cell array.
G = cell(1,16);
for m = 1:16
G{m} = NUM(m);
end
| Nesting Cell Arrays | Cell Arrays of Structures | ![]() |