Finding the maximum value of a matrix contained in a cell
11 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!