この(互換性のあるすべてのバージョン)を行う最も簡単な方法は、単にセル配列を受け入れることができ、「文字列が比較」んstrcmp
を、使用することです。
ワンライナー
indexresult = find(strcmp(C(:,1), 'name') & strcmp(C(:,3), '23'));
% indexresult = [1; 4; 6];
説明
% Get logical array of rows where first column is 'name'
logicalname = strcmp(C(:,1), 'name');
% Get logical array of rows where third column is '23'
logical23 = strcmp(C(:,3), '23');
% Get logical array where both of the above are true, using and (&)
logicalname23 = strcmp(C(:,1), 'name') & strcmp(C(:,3), '23');
% Get indices from logical array using find
indexresult = find(strcmp(C(:,1), 'name') & strcmp(C(:,3), '23'));
% If you wanted a row vector instead of column vector, just transpose too
indexresult = find(strcmp(C(:,1), 'name') & strcmp(C(:,3), '23')).';
あなたは('name', 'NAME', 'Name', ...
に一致する)大文字と小文字を区別したい場合は、代わりにstrcmp
のstrcmpi
を使用しています。
'strfindは' 'name1234 'のように' '' name ''を含む文字列にもマッチすることに注意してください – Wolfie