Cannot find string in table matlab
3 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find this string "+972 52-697-8081" in a the table namesnumbers as can be seen in the picture,it exists in the table though it returns 0 in the specific place where it exists.the line i used is
IndexC = strfind(namesnumbers{:,:},string(newnum) );
When i tried contains not a variable it did find the index though as a specific number
IndexC = strfind(namesnumbers{:,:},"+972 52-697-8081" );
What am I doing wrong?
link to the excel sheets:
https://www.transfernow.net/dl/20210719GmyiVZBY/MoeMJdfv
the code:
finalnames=readtable("names1example.xlsx");
m1="101.xlsx";
t=readtable(m1);
m=t(4:end,:);
[size1,~]=size(t);
numbers=t(:,3);
namesnumbers=finalnames(:,3);
for k=3:size1
number= numbers{k,1};
IndexC = strfind(namesnumbers{:,:},string(number) );
Index = find(not(cellfun('isempty',IndexC)));
gender=finalnames(Index,2);
name=finalnames(Index,1);
end
t(:,4)= (name);
t(:,5)= (gender);
t(:,6:end)=m;
m2=append("H",m1);
writetable(t,m2);
[2]: https://i.stack.imgur.com/zumqE.png
1 件のコメント
Peter Perkins
2021 年 7 月 27 日
Tomer, there's something funny going in your code. strfind returns a vector of indices, yet you are passing that to cellfun. That can't be right.
In addition, you have a table with only one variable in it. There' not much point in that, you may as well just extract the one variable. As, I think, text. I'd recommend a string array, not a cell array of char rows.
回答 (1 件)
Hrishikesh Borate
2021 年 7 月 22 日
Hi,
Modifying the assignment of variable IndexC can be a possible approach to find the string in the table.
IndexC = cellfun(@(s) strfind(number{1}, s),namesnumbers{:,:},'UniformOutput',false);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!