フィルターのクリア

Compare values in cell array with a threshold value.

3 ビュー (過去 30 日間)
lucksBi
lucksBi 2017 年 6 月 16 日
コメント済み: lucksBi 2017 年 6 月 16 日
hey
i have 2 cell arrays like this:
A= {[NaN,1.8,3,NaN,4];[2.6,NaN,NaN,2.9,4];[NaN,3,2,2,NaN]}
B={[5x5 cell];[6x5 cell];[4x5 cell]}
Thresh=10
elements in B are:
B{1,1}= {0,21,14,0,0;0,10,0,0,4;0,11,0,0,0;0,0,1,0,3;0,8,0,0,0}
B{2,1}= {13,0,0,0;0,0,0,13;9,0,0,0;5,0,0,3;0,0,0,0}
B{3,1}= {0,0,2;0,0,0;0,0,12;0,5,21;7,0,0,0}
For each non-NaN value column index in each cell of A, it will display and count values greater & less than 'thresh' in corresponding cell of B.
e.g. in first cell of A, 2 is first non-NaN value, so it will check in 2nd column of B{1,1} which is {21;10;11;0;8} the values which are greater than thresh value (which are 21 and 11). And Count them (which are 2 here). And also values less and equal to the thresh value (which are 8 and 10) and count them.
Similarly next non-NaN index is 3 so it will repeat the process for 3rd column of B{1,1}
Please help.
  2 件のコメント
Julian Hapke
Julian Hapke 2017 年 6 月 16 日
I can't execute your example, because there is a dimension mismatch in the assignment of B{3,1}. I recommend to use plain arrays instead of cell arrays inside of B, so replace curly braces on the rhs with []. Then a simple loop should do the trick
lucksBi
lucksBi 2017 年 6 月 16 日
yes I have tried that but actual arrays are quite large which makes code inefficient by using loops. Thanks for your time.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 16 日
編集済み: Andrei Bobrov 2017 年 6 月 16 日
% input
A= {[NaN,1.8,3,NaN,4];[2.6,NaN,NaN,2.9,4];[NaN,3,2,2,NaN]};
Thresh=10;
B = arrayfun(@(x)num2cell(randi([0 23],x,5).*(rand(x,5) > .5)),[5;6;4],'un',0);
% solution
Bd = cellfun(@cell2mat,B,'un',0);
out = cellfun(@(x,y)histc(y(:,~isnan(x)),[eps(1e4),Thresh+eps(1e4),inf]),A,Bd,'un',0);
out = cellfun(@(x)x([2,1],:),out,'un',0);
  4 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 6 月 16 日
編集済み: Andrei Bobrov 2017 年 6 月 16 日
D = cat(3,out{:});
gth = squeeze(D(1,:,:))'; % greater than
lth = squeeze(D(2,:,:))'; % less than
lucksBi
lucksBi 2017 年 6 月 16 日
Yes i have tried this earlier but it gives following error
Error using cat
Dimensions of matrices being concatenated are not consistent.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by