create cell array and extract the highest value in matlab

To create a cell array in Matlab, you can use the cell() function:

main.m
A = cell(3, 2);
16 chars
2 lines

This will create a 3x2 cell array A, where each cell can contain any type of data, including numbers, strings, or even other arrays.

To extract the highest value from a cell array, you can first convert it to either a numeric or cell array, depending on the contents of the cells. Then you can use the max() function to find the highest value.

Here's an example that extracts the highest value from a 3x2 cell array:

main.m
B = {1, 2, 3; 4, 5, 6};
C = cell2mat(B); % convert to numeric array
max_val = max(C(:)); % extract highest value
113 chars
4 lines

In this example, B is a 3x2 cell array containing numbers. We first convert it to a numeric array using cell2mat(), which concatenates the contents of the cells into a single array. Then we use the max() function to find the highest value. The (:) operator is used to linearize the array into a single column before passing it to max().

related categories

gistlibby LogSnag