# Smartly search between tables

1 ビュー (過去 30 日間)
federico nutarelli 2021 年 7 月 2 日

Hi all,
so I have two datasets made of 0 and 1. The two datasets (in the form of matlab tables), call them D1 and D2 are 1229x119. D1 contains true values and D2 predictions. Each column of D1 and D2 has a country name c1,c2,c3,...,c119. What I would like to do is to recover, for each country in a subset, say [c3,c6,c12,c45,c117], the row index for these countries whenever D2 has entry 1 and D1 has entry 0.
The desired output is a cell array indexed by country (say row_index{ck} for k=3,6,12,45,117) whose values are the row indices for which D2=1 and D1=0, s for instance say this happens fr rows 39, 678, 1220 for cuntry c6, I would like too obtain:
row_index{c6}=[39,678,1220]
##### 3 件のコメント表示非表示 2 件の古いコメント
Peter Perkins 2021 年 7 月 29 日
dpb, it sounds like the countries are the variables in these tables, so I would think this is a varfun problem, not rowfun.

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

### 回答 (1 件)

Peter Perkins 2021 年 7 月 29 日

This would be trivial if varfun accepted more than one table input, but it doesn't do that. But you can make one table that looks for your condition, and apply varfun to that:
>> D1 = array2table(randi([0 1],10,3),"VariableNames",["US" "UK" "UAE"]);
>> D2 = array2table(randi([0 1],10,3),"VariableNames",["US" "UK" "UAE"]);
>> D12 = array2table(D1{:,:} & ~D2{:,:})
D12 =
10×3 table
Var1 Var2 Var3
_____ _____ _____
true true false
false false false
true false false
false false false
false false false
false false true
false true true
true true true
true true true
false true false
>> varfun(@(x) find(x), D12, "OutputFormat","cell")
ans =
1×3 cell array
{4×1 double} {5×1 double} {4×1 double}
1229x119 isn't gigantic, so probably no memory issues there. But alternatively,
for i = 1:width(D1)
c{i} = find(D1.(i) & ~D2.(i));
end

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

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by