find a word in a sentence in a cell
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Amr Hashem
am 10 Mai 2015
Kommentiert: Stephen23
am 18 Mai 2015
i want to search for all the rows (:,6)that contain a specific word
i try :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149991/image.jpeg)
[num text alldata] = xlsread('result.xlsx','1'); % import excel file
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....!
SOS...any help please.
1 Kommentar
Akzeptierte Antwort
Star Strider
am 10 Mai 2015
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.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!