Cannot find string in table matlab

6 Ansichten (letzte 30 Tage)
Tomer Ron
Tomer Ron am 19 Jul. 2021
Kommentiert: Peter Perkins am 27 Jul. 2021
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 Kommentar
Peter Perkins
Peter Perkins am 27 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Hrishikesh Borate
Hrishikesh Borate am 22 Jul. 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);
For more information, refer cellfun.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by