フィルターのクリア

How to show only the same variable

1 回表示 (過去 30 日間)
Alikouider
Alikouider 2021 年 12 月 11 日
コメント済み: Alikouider 2021 年 12 月 12 日
Hello,
I have a .mat file as following
Name adress company
BOB london BIM
Alfred Paris BOB
John BOB CEF
I would like to display only the duplicate variable in or order to create this new .mat file
Name adress company
BOB
BOB
BOB
If someone have an idea to create the adapted code?
Thanks in advance
  5 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 12 日
You accepted Walter's answer, so we assume everything is working perfectly now.
Alikouider
Alikouider 2021 年 12 月 12 日
I accepted walter's code
But chunru's code is more adapted to what I was looking for
walter's code is more complicated to adapt for the moment
so I focused on chunru's code and i saw that the duplication of the entries didn't work
dup = mode(Tcv); % duplicated entries (using mode)
this function doesn't seem to work
the same names (not variables) are randomly put in the table
I should keep the names which are the same and that appear in more than one variable.
Thanks for your understanding

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 11 日
common_values = intersect(intersect(Name, adress), company);
N = length(Name);
NName = strings(N, 1);
mask = ismember(Name, common_values);
NName(mask) = Name(mask);
Nadress = strings(N, 1);
mask = ismember(adress, common_values);
Nadress(mask) = adress(mask);
Ncompany = strings(N, 1);
mask = ismember(company, common_values);
Ncompany(mask) = company(mask);
output = table(Nname, Nadress, Ncompany, 'VariableNames', {'Name', 'adress', 'company'});
  8 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 12 日
A = readtable('DataFilter.xlsx','TextType','string');
names_by_var = varfun(@unique, A, 'OutputFormat', 'cell');
[G, ID] = findgroups(categorical({names_by_var{:}}));
counts = accumarray(G, 1);
names_with_dups = ID(counts>1);
is_dup = varfun(@(V) ismember(categorical(V), names_with_dups), A, 'OutputFormat', 'uniform');
Aarray = table2array(A);
B = strings(size(Aarray));
B(is_dup) = Aarray(is_dup);
Alikouider
Alikouider 2021 年 12 月 12 日
Error using categorical could not find unique values in DATA using the UNIQUE function.
Error in [G, ID] = findgroups(categorical({names_by_var{:}}));
Caused by:
Error using cell/unique Cell array input must be a cell array of character vectors.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by