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!