Finding the maximum value of a matrix contained in a cell

11 ビュー (過去 30 日間)
Optical_Stress
Optical_Stress 2017 年 4 月 6 日
コメント済み: Aditi Vedalankar 2018 年 6 月 11 日
I have a 5-by-1 cell called C. I can extract the first matrix by C{1,1}{1,1};
When I say M=max((M{1,1}{1,1})) it returns a vector rather than a single integer. The matrix is a matrix of Intensities represented as uint8.
I believe it returns the maximum value of each column rather than the entire matrix. I can resolve this issue by finding the max of 'M' but was wondering if there was a single step method instead.
I had also tried M=max(cell2mat(M{1,1}{1,1})); but this did not work and i received error:
Cell contents reference from a non-cell array object.

採用された回答

Guillaume
Guillaume 2017 年 4 月 6 日
Note: avoid using subscript (2D) indexing on vectors. Prefer linear (1D) indexing. If C is a vector with 5 elements, C{5} will work whether or not it's a 5x1 or 5x1 cell array, whereas C{5,1} will error on a 1x5 cell array.
Note 2: "I have a 5-by-1 cell called C. I can extract the first matrix by C{1,1}{1,1};" The first element of C is C{1} (or C{1, 1} using subscript indexing). If you have to use C{1}{1} then the cells of your cell array are themselves cell arrays. That does not sound like it was intended from your description.
Anyway, If you want the max as a one liner:
M = max(reshape(C{1}{1}, 1, [])); %reshape the matrix into a vector before taking the max
However, I would recommend splitting the above in two for clarity
img = C{1}{1}; %get content of cell
M = max(img(:)); %get the max of all pixels
  2 件のコメント
Optical_Stress
Optical_Stress 2017 年 4 月 6 日
thanks!
Aditi Vedalankar
Aditi Vedalankar 2018 年 6 月 11 日
But if the cell is say 2 X 8 and every element of cell is a matrix, then how will we find the max of every matrix

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by