How to show only the same variable
Afficher commentaires plus anciens
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 commentaires
% Data
varnames = ["Name" "adress" "company"];
data = ["BOB" "london" "BIM"
"Alfred" "Paris" "BOB"
"John" "BOB" "CEF"];
T = array2table(data, 'VariableNames', varnames);
% Find the duplicate one
Tc = categorical(T{:,:}); % convert from string to categorical
Tcv = Tc(:); % make it into a long vector
dup = mode(Tcv); % duplicated entries (using mode)
% The location of duplicate one
idx = Tc == dup;
% Generate output
Tout = strings(size(data));
Tout(idx) = dup;
Tout = array2table(Tout, 'VariableNames', varnames)
Ali
le 11 Déc 2021
Ali
le 11 Déc 2021
Image Analyst
le 12 Déc 2021
You accepted Walter's answer, so we assume everything is working perfectly now.
Ali
le 12 Déc 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Import and Network Parameters dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!