Using the C++ Math Library | ![]() ![]() |
Displaying the Contents of a Cell Array
The C++ output operator (<<
) is used to direct a value to an output stream such as the predefined ostream cout (standard output). For numeric arrays, the output operator displays the contents of each array element. However, for cell arrays, the output operator displays the contents of a cell only if the value stored there is a MATLAB character array or scalar array. For cells containing multidimensional arrays, cell arrays or other MATLAB arrays, the output operator only displays the size of the array stored in the cell.
To display the contents of each cell in a cell array, you must use the celldisp()
routine. To illustrate, the following code fragment creates a cell array that contains a MATLAB character array, a scalar array, and several multidimensional arrays. The example then prints out the cell array using the output operator and celldisp()
.
mwArray C = vertcat(cellhcat("jon",5), cellhcat(magic(3), ones(2,3,2))); cout << "cout output:\n" << C << endl; cout << "celldisp() output:\n" << endl; celldisp(C,"C");
This code produces the following output:
cout output:
'jon' [ 5]
[3x3 double] [2x2 double]
celldisp() output: C{1,1} = jon C{2,1} = 8 1 6 3 5 7 4 9 2 C{1,2} = 5 C{2,2} = (:,:,1) = 1 1 1 1 1 1 (:,:,2) = 1 1 1 1 1 1
![]() | Creating Cell Arrays | MATLAB Structures | ![]() |