table内の文字列の有無の存在を確認する方法
이전 댓글 표시
답변 (1개)
任意の文字列がテーブルのどのコラムにあるのかもわからないという想定で書いています。
------------------------------
データを準備します
T = table(categorical({'M';'F';'M';'M'}),[45;32;34;54],...
{'NY';'CA';'MA';'CA'},logical([1;0;0;1]),...
'VariableNames',{'Gender','Age','State','Vote'})
ここでCAという文字が何処かにないか探します
word = 'CA';
idx = table2array(varfun(@(x) strcmp(string(x),word),T))
find関数で何行目にあるのか探し、該当する部分を表示させます。
[x,~] = find(idx);
T(x,:)
댓글 수: 1
任意の文字列がテーブルのどのコラムにあるわかる場合はこうですね。
T = table(categorical({'M';'F';'M';'M'}),[45;32;34;54],...
{'NY';'CA';'MA';'CA'},logical([1;0;0;1]),...
'VariableNames',{'Gender','Age','State','Vote'})
idx = find(strcmp(T.State,'CA')); % table の'State'列に'CA'がある行を検索
T(idx, :)
카테고리
도움말 센터 및 File Exchange에서 table에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!