table内の文字列の有無の存在を確認する方法
39 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
テーブル内の任意の文字列の有無を確認する方法があれば教えて下さい。
0 Commenti
Risposte (1)
Hernia Baby
il 9 Ago 2022
任意の文字列がテーブルのどのコラムにあるのかもわからないという想定で書いています。
------------------------------
データを準備します
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 Commento
Atsushi Ueno
il 9 Ago 2022
任意の文字列がテーブルのどのコラムにあるわかる場合はこうですね。
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, :)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!