How to apply a threshold value to the cell array
3 次查看(过去 30 天)
显示 更早的评论
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
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
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!