필터 지우기
필터 지우기

How to search in a text cell by a word ?

조회 수: 2 (최근 30일)
Amr Hashem
Amr Hashem 2015년 5월 9일
댓글: Star Strider 2015년 5월 10일
i have a large data (text and numbers), i want to search for a word in a specific cell (contaning text) of a coloumn in all rows. a(:,6)
example
and then copy all the rows containing the word in a new file.
how i can do this ?
i try
j=1 for i=1:size(data,1) if isequal (data{i,6}, ' the word') d(j)=i j=j+i end end newdata=data(D,:);

채택된 답변

Star Strider
Star Strider 2015년 5월 9일
The standard comparison functions used with numeric variables don’t work with strings. Consider using strcmp or its many friends (most of them linked to on that page). One of them should work for you.
  댓글 수: 2
Amr Hashem
Amr Hashem 2015년 5월 10일
i am trying:
[num text alldata] = xlsread('result.xlsx','1');
j=1;
k=1;
for i=1:size(alldata,1)
d = regexp(alldata{i,6},'[ ]*','split') % this split sentences but didn't save
for L=1:length(d)
idx(k)=l;
k=k+1; end
if isequal (alldata{i,6},'battery') % search for word "battery"
defs(j)=i;
j=j+1;
end end
data=alldata(defs,:);
but it didn't work....!
could you please help me?
Star Strider
Star Strider 2015년 5월 10일
I don’t have your data so I can’t run your code or test this, but see if:
if strcmpi(alldata{i,6},'battery') % search for word "battery"
improves your code.
It uses the strcmpi (case-insensitive string comparison) to do the test.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by