How to apply a threshold value to the cell array

조회 수: 9 (최근 30일)
Abdulhakim Alezzi
Abdulhakim Alezzi 2021년 2월 3일
댓글: Abdulhakim Alezzi 2021년 2월 3일
Hi Friends,
I have a cell array matrix with C= 1*22. I want to apply a thresold to the cell array, all values less than (0.2) must be set to zero (0). The output dimention must be the same dimention of input cell array (1*22).
1- i have converted the cell to double
2- Applied the threshold
3- convert back the double to cell
I have applied this code, but could not got a cell with (1*22).
X=str2double(C); % converted the cell to double
X(X <0.2)=0; % Applied the threshold
C = num2cell(X); % convert back the double to cell
  댓글 수: 2
Matt J
Matt J 2021년 2월 3일
Works fine for me:
C=cellstr( rand(1,22)+"" );%Fake
X=str2double(C); % converted the cell to double
X(X <0.2)=0; % Applied the threshold
C = num2cell(X); % convert back the double to cell
whos C
Name Size Bytes Class Attributes C 1x22 2464 cell
Abdulhakim Alezzi
Abdulhakim Alezzi 2021년 2월 3일
Hi Matt,
The issue here in my matrix that i have inside the cell 22 matrices (each matrix inside every colomn in the cell is 30*30*20) as shown in the attached picture.

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

채택된 답변

Steve Eddins
Steve Eddins 2021년 2월 3일
I think writing a for-loop would be most straightforward way to go. Something like this:
for k = 1:numel(C)
C_k = C{k};
C_k(C_k < 0.2) = 0;
C{k} = C_k;
end
  댓글 수: 1
Abdulhakim Alezzi
Abdulhakim Alezzi 2021년 2월 3일
Dear Mr. Steve Eddins,
Thank you very much, It is really helping.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by