How to show only the same variable
이전 댓글 표시
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
% 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
2021년 12월 11일
Ali
2021년 12월 11일
Image Analyst
2021년 12월 12일
You accepted Walter's answer, so we assume everything is working perfectly now.
Ali
2021년 12월 12일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import and Network Parameters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!