Replacing values in cell array in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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));
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!