필터 지우기
필터 지우기

Replacing values in cell array in for loop

조회 수: 6 (최근 30일)
ARN
ARN 2020년 5월 18일
댓글: Stephen23 2020년 5월 18일
I have cell array {1x5} and each cell contains 1000x1000 matrix. I need to find values which are less than 100 and replace it with 100. I tried with cellfun but i couldn't get the right solution.
Can anyone help me with that?
Y(cellfun(@(Y) Y < spect_threshold, spect_threshold, 'UniformOutput', false));

채택된 답변

Stephen23
Stephen23 2020년 5월 18일
편집: Stephen23 2020년 5월 18일
It is simpler and more efficient to use max:
F = @(m) max(m,spect_threshold);
Y = cellfun(F, Y, 'UniformOutput', false);
  댓글 수: 2
ARN
ARN 2020년 5월 18일
What does the first line mean? can you please eleborate.
Thanks
Stephen23
Stephen23 2020년 5월 18일
The first line defines an anonymous function (called "lambda function" in some other languages):
The function has one input m and for each element in m returns either its value or spect_threshold, whichever may be greater. cellfun applies that function to each matrix in the cell array.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by