필터 지우기
필터 지우기

How to find maximum value from different array in spesific dimension

조회 수: 2 (최근 30일)
Nico S
Nico S 2016년 1월 18일
편집: Stephen23 2016년 1월 18일
i have a variable array which consist of lets say 1x2 cell i want to find the maximum value for each column (combination of cell1 and cell2 value) example:
so, the maximum for column 1 is 1.7508 column 2 is 1.0713 column 3 is 5.8888
i tried using max(), but cant figure out how to find maximum value from different location(cell) please help..
thanks in advance

답변 (2개)

Stalin Samuel
Stalin Samuel 2016년 1월 18일
s1{:} = rand(3)% cell 1
s2{:} = rand(3)% cell 2
data = [s1{:};s2{:}] %combining both cell data
Result = max(data)
  댓글 수: 4
Stephen23
Stephen23 2016년 1월 18일
편집: Stephen23 2016년 1월 18일
Yes, but it will be slow and buggy.
MATLAB is optimized to work fastest on numeric arrays, so whatever code you write will be slower than this solution.
We often get questions from beginners who have stuck all of their numeric data in cell arrays, and then want to perform some numeric operations on the total data. Not surprisingly the simplest, fastest and neatest solution is to take all of the numeric data out of the cell array and put it all in one numeric array. Performing the numeric operation is then usually quite trivial, like in this case. Because that is what numeric arrays are for.
Note on terminology: you write that "combining both into one cell", but actually the combined data are in a numeric array, not a cell array. Cell arrays have cells, numeric arrays have elements. Using the correct terminology makes it easier to communicate on this forum.
Guillaume
Guillaume 2016년 1월 18일
A slightly more generic way of concatenating the data:
c = {rand(50, 3); rand(50, 3)}; %demo data
m = vertcat(c{:});
However, as Stephen's said, if the matrices in the cell arrays are all the same size, it would be wiser to hold the data into a plain array to start with.

댓글을 달려면 로그인하십시오.


Stephen23
Stephen23 2016년 1월 18일
편집: Stephen23 2016년 1월 18일
This is the neatest solution, with the numeric arrays in one cell array:
C{1} = rand(3);
C{2} = rand(3);
max(vertcat(C{:}),[],1)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by