Split values in an cell array by using a threshold

Hello everyone.I have a cell array of variable (A), 1x91.In each cell it has an array of size 256x256.I would like to threshold each array so that elements lesser than or greater than a given threshold value are stored in different variable.Your help is really appreciated.

 採用された回答

Matt J
Matt J 2020 年 5 月 19 日
編集済み: Matt J 2020 年 5 月 19 日

0 投票

One way,
A_lower = cellfun(@(x) x(x<threshold), A, 'uni',0);
A_upper = cellfun(@(x) x(x>threshold), A, 'uni',0);

4 件のコメント

Sabari G
Sabari G 2020 年 5 月 19 日
Thanks for your respone.Here i get empty cell array.Myy threshold value is 0.5.
Sabari G
Sabari G 2020 年 5 月 19 日
It doesnt work.It shows error message like this.can u suggest me another way and I have one doubt in the code..what does the X means in the above code.
Error using cellfun
Input #2 expected to be a cell array, was double instead.
Error in duru (line 36)
A_lower = cellfun(@(x) x(x<threshold), A, 'uni',0);.
Matt J
Matt J 2020 年 5 月 19 日
In the case where you got empty matrices, it because none of your data fall below 0.5. In the case where you got error messages, it is because your A variable is not a cell array.
Below is a small example showing that the technique will work when properly applied:
>> A={rand(3), rand(3)}; A{:}
ans =
0.5407 0.9734 0.1941
0.8929 0.6006 0.7933
0.9092 0.8582 0.8144
ans =
0.5087 0.0331 0.7163
0.3399 0.1797 0.3758
0.6815 0.7166 0.3589
>> A_lower = cellfun(@(x) x(x<0.5), A, 'uni',0); A_lower{:}
ans =
0.1941
ans =
0.3399
0.0331
0.1797
0.3758
0.3589
Sabari G
Sabari G 2020 年 5 月 20 日
Thanks a lot!! It works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品

リリース

R2018a

質問済み:

2020 年 5 月 19 日

コメント済み:

2020 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by