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!