필터 지우기
필터 지우기

Thresholding Matrix Within Cell Array

조회 수: 1 (최근 30일)
itend
itend 2017년 8월 29일
댓글: Cam Salzberger 2017년 8월 31일
Hello,
I have a cell array called output. Each cell within output contains a 1024 x 1024 matrix. I would like to threshold each matrix so that elements below a given value are set to NaN.
I tried using:
output(output < 100000) = NaN;
However, I feel that this is the wrong approach. Intuitively, I want to use a for loop, however, I don't think that will be the most efficient method possible.
Thoughts? Suggestions?
Thanks :)
  댓글 수: 1
Image Analyst
Image Analyst 2017년 8월 29일
Why are you using a cell array instead of a regular 3-D array, and why did you want to set it to NaN? What are you going to do with the output array after that?

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

채택된 답변

Cam Salzberger
Cam Salzberger 2017년 8월 29일
편집: Cam Salzberger 2017년 8월 31일
cellfun is your friend here. You can create a local, nested, or regular function to do the NaN-setting, and then just apply it to each element of the cell array:
function A = filterMatrix(A,thresh)
A(A < thresh) = NaN;
end
Then call it with:
filteredOutput = cellfun(@(A) filterMatrix(A, 100000), output, 'UniformOutput', false);
-Cam
  댓글 수: 2
itend
itend 2017년 8월 29일
Thank you for your response.
Unfortunately, it produced an error:
f = @(A) A(A < 100000) = NaN;
Error: The expression to the left of the equals sign is not a valid target for an assignment.
What do you think?
Cam Salzberger
Cam Salzberger 2017년 8월 31일
Ah, sorry about that. I forgot you can't do assignment in anonymous functions. Easy enough to make a separate function for it though. I've edited my answer above to function correctly.
Image Analyst has a point though; could you not just create a 3-D matrix originally? That would allow you to do the whole thing in a single call. Also would take less overhead, though it will need a larger contiguous memory chunk.
-Cam

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

추가 답변 (0개)

카테고리

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