简体   繁体   English

MatLab在两个像元阵列中查找具有特定值的像元

[英]MatLab find cells with specific values in two cell arrays

I want to find cells, which are at the same position in two different cell arrays and which have specific values. 我想找到位于两个不同单元格阵列中相同位置且具有特定值的单元格。

The two cell arrays have the following structure: 这两个单元格数组具有以下结构:

cell array C1= cell(20,1) . 单元格数组C1= cell(20,1) In each cell there is another cell cell(8129,8) holding double values in the range of [0,1]. 在每个单元格中,还有另一个单元cell(8129,8)保持[0,1]范围内的双cell(8129,8)值。

Cell array C2= cell(20,1) . 单元格数组C2= cell(20,1) In each cell there is another cell cell(8192,8) also holding double values in the range of [0,1]. 在每个像元中,还有另一个像元cell(8192,8)也保持[0,1]范围内的双cell(8192,8)值。

I know want to find those cells, which (1) have a specific value that I determine (eg C1_value = 0.8 and C2_value = 0.85) and (2) are at the same position in the respective sub cell (!) array (eg C1{2}(736) == 0.8 and C2(19)(736) == 0.85). 我知道要查找那些单元格,这些单元格(1)具有我确定的特定值(例如C1_value = 0.8和C2_value = 0.85),而(2)在相应子单元格(!)数组中的相同位置(例如C1 {2}(736)== 0.8和C2(19)(736)== 0.85)。 NOTE: The same position only refers to the subcell arrays ( cell(8192,8) ) not the "main" cell arrays C1(:) and C2(:) 注意:相同的位置仅引用子cell(8192,8)数组( cell(8192,8) ),而不是“主”单元格数组C1(:)C2(:)

Thanks in advance! 提前致谢!

See if this approach works for you - 看看这种方法是否对您有用-

sz = cell2mat(cellfun(@size,C1(1),'uni',0))
row1 = sz(1);
col1 = sz(2);

t1 = reshape(horzcat(C1{:}),row1,col1,[])
t2 = reshape(horzcat(C2{:}),row1,col1,[])

b1 = t1==C1_value
b2 = t2==C2_value

tt1 = reshape(b1,row1*col1,[])' %//'
tt2 = reshape(b2,row1*col1,[])' %//'

tt22 = permute(tt2,[3 2 1])
tt3 = bsxfun(@and,tt1,tt22)
[C1_cellnum,subcellnum,C2_cellnum] = ind2sub(size(tt3),find(tt3)) %// outputs

Thus, with your sample data, you must have - 因此,使用样本数据,您必须-

C1_cellnum as 2 , C2_cellnum as 19 and subcellnum as 736 . C1_cellnum2C2_cellnum19 ,子subcellnum736

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM