How to select the maximum value for each row in cell type variable in matlab?

조회 수: 1 (최근 30일)
I have a cell type variable(Final) with dimension 279*100. I want to create a new matrix of 279*1 dimension such that i can have only the maximum value of each row in the new matrix. Can anyone please help me do this?
Thank You

채택된 답변

Jan
Jan 2021년 1월 27일
편집: Jan 2021년 1월 27일
Some rows of the cell Final contain only empty elements. What do you want to be the output in this case? If NaN is sufficient:
nRow = size(Final, 1);
FinalMax = nan(nRow, 1);
for k = 1:nRow
row = [Final{k, :}];
if ~isempty(row)
FinalMax(k) = max(row);
end
end
  댓글 수: 2
Niraj Bal Tamang
Niraj Bal Tamang 2021년 1월 27일
thank you so much. can i just replace the NaN with 0 so that it won't give any error in further mathematical calculations?
Jan
Jan 2021년 2월 8일
Of course. Simply change "FinalMax = nan(nRow, 1);" to "FinalMax = zeros(nRow, 1);

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

추가 답변 (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