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
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by