Borrar filtros
Borrar filtros

Pattern matching problem

4 visualizaciones (últimos 30 días)
B_Richardson
B_Richardson el 30 de Jun. de 2011
I realize my previous post was way too long so here is a simpler version:
%callback for listbox1
%expirement%
pattern1 = 'SHC';
pattern2 = 'SLR';
pattern3 = 'RHA';
indexselected = get(handles.listbox1,'Value');
list = get(handles.listbox1,'String');
itemselected = list{indexselected};
if regexp(itemselected, pattern1)
[substance,substance]=xlsread('C:\Users\ecorbett\Documents\VCoachData\Labels\SHC.xlsx','Sheet 1','A1:A10000');
set(handles.listbox3,'string',substance);
msgbox('The listbox has been updated.','Update Complete','help');
elseif regexp(itemselected, pattern2)
[substance,substance]=xlsread('C:\Users\ecorbett\Documents\VCoachData\Labels\SLR.xlsx','Sheet 1','A1:A10000');
set(handles.listbox3,'string',substance);
msgbox('The listbox has been updated.','Update Complete','help');
elseif regexp(itemselected, pattern3)
[substance,substance]=xlsread('C:\Users\ecorbett\Documents\VCoachData\Labels\RHA.xlsx','Sheet 1','A1:A10000');
set(handles.listbox3,'string',substance);
msgbox('The listbox has been updated.','Update Complete','help');
end
the strings in listbox1 are file names:
SHC_RL_S1_0004_v1.59806163.avi SHC_RL_S2_0004_v1.59806163.avi RHA_RL_S3_0004_v1.59806163.avi RHA_LL_S1_0004_v1.59806163.avi SLR_RL_S3_0004_v1.59806163.avi SLR_LL_S1_0004_v1.59806163.avi
right now the code produces no errors but does not update listbox3

Respuesta aceptada

Matt Fig
Matt Fig el 30 de Jun. de 2011
I would use STRFIND instead of REGEXP.
list = 'SHC_RL_S1_0004_v1.59806163.avi SHC_RL_S2_0004_v1.59806163.avi RHA_RL_S3_0004_v1.59806163.avi '
pattern1 = 'SHC';
if strfind(list,pattern1)
disp('Found it!')
end
But now try with:
pattern1 = 'afddsafsa';
  8 comentarios
Matt Fig
Matt Fig el 1 de Jul. de 2011
Again, I would not use regular expressions. A simple match will work if you only have 3 patterns. Look at my example above. There is no need to use regular expressions when you know the exact match before hand.
B_Richardson
B_Richardson el 1 de Jul. de 2011
Nevermind Matt. I got it to work. something is wrong with my excel files now. But the pattern matching is working. Thanks a million!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Text Analytics Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by