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

 Akzeptierte Antwort

Matt Fig
Matt Fig am 30 Jun. 2011

1 Stimme

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 Kommentare

B_Richardson
B_Richardson am 30 Jun. 2011
According to HELP, it appears that STRFIND has to find an exact match between 2 strings? In my case im just looking for SHC, RHA, or SLR.
Matt Fig
Matt Fig am 30 Jun. 2011
That is not what the help says.
K = STRFIND(TEXT,PATTERN) returns the starting indices of any
occurrences of the string PATTERN in the string TEXT.
So if PATTERN appears at all in TEXT then you will get a number back. If not, you will get an empty array, which will not pass the IF statement.
B_Richardson
B_Richardson am 30 Jun. 2011
pattern1 = 'SHC\W';
pattern2 = 'SLR\W';
pattern3 = 'RHA\W';
indexselected = get(handles.listbox1,'Value');
list = get(handles.listbox1,'String');
itemselected = list{indexselected};
if STRFIND(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 STRFIND(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 STRFIND(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
%END%
Still produces no results. Is there something wrong with my regular expression?
Matt Fig
Matt Fig am 30 Jun. 2011
Does your itemselected have ALL of this in it: 'SHC\W'
The examples you gave did not have the \W so it is no wonder no matches are found. Did you see my example above?
B_Richardson
B_Richardson am 30 Jun. 2011
The full path to the video is:
C:\Users\ecorbett\Documents\VCoachData\0008_Capture_10152009\Video\RHA
B_Richardson
B_Richardson am 30 Jun. 2011
Actually, I think I was confused (as always) as to what the movieplayer function was sending to the listbox. It does look for the fullpath, but I now see that the contents in the box are:
SHC_LL_S1_0008_V5.5983338494.avi
So what regular expression would I need to match this pattern?
Matt Fig
Matt Fig am 1 Jul. 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 am 1 Jul. 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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by