Converting Cell to Matrix to use Max Function

Hello! I have a cell array of dimensions 1x1121, and I need the find the maximum value contained in this array. Since the max function only works on matrices, I was hoping to convert this cell array into a matrix. However, I keep getting an error on the dimensions when I use cell2mat. I have also tried using cell2mat(cellArray(1,:)) and as well initializing a matrix of the same dimensions to put the values (which are of type double into). Any input is greatly appreciated, thank you in advance.

 採用された回答

Matt Fig
Matt Fig 2011 年 5 月 25 日

1 投票

MYCELL = {magic(3) magic(5) magic(6)}
mx = cellfun(@(x) max(x(:)),MYCELL)
mx has the maximum element for each individual cell. If you need the overall maximum, use MAX on mx.

2 件のコメント

A
A 2011 年 5 月 25 日
Thanks, Matt! Why did you use the magic functions?
Matt Fig
Matt Fig 2011 年 5 月 25 日
Just to have an easy example to show you. No particular reason.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

A
A
2011 年 5 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by