minimum of different sized cell arrays using cell2mat error
Show older comments
How do i find the overall minimum of a cell array, cell2mat gives error.
Y= {[100 200] [50 100] [20] [30 140];
[10 130] [40] [60 200] [30]};
min(cell2mat(Y))
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 78)
m = cat(1,m{:});
Accepted Answer
More Answers (2)
Stephen23
on 24 Nov 2017
>> min([Y{:}])
ans = 10
1 Comment
Jos (10584)
on 24 Nov 2017
Nice. I thought of that too, but it will fail when some cells of Y are not row-vectors.
Jan
on 24 Nov 2017
The fast C-Mex function FEX: Cell2Vec converts the contents of the cell to a vector independent from the shapes of the cell elements:
Y = {[100 200] [50 100] [20] [30 140]; ...
[10 130] [40] [60 200] [30]};
C = Cell2Vec(Y);
min(C)
[Min, Max, MinIndex, MaxIndex, MinArg, MaxArg] = MinMaxElem(Y{:})
This searches the max and the indices also. NOTE: This is not faster than min and max of modern Matlab versions anymore. But perhaps more convenient for your case.
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!