Cannot find string in table matlab
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Peter Perkins
le 27 Juil 2021
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.
Réponses (1)
Hrishikesh Borate
le 22 Juil 2021
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 commentaires
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!