compare 3 column values and display the 4th column value as output

2 Ansichten (letzte 30 Tage)
I want to create a GUI with 3 drop down list with some values. when we select the input values from the drop down list, it has to search the values from excel sheet. when both the input values are matched in the excel sheet then it has to display the corresponding 4th column value.
example
A B C D
----------------------------------
xxx xxx xxx First row
xxz yyy abc Second row
xyz yyy zzz third row
yyy xxx xyz Fourth row
zzz abc xxx fifth row
these are the values in excel sheet. suppose if i select
xxx yyy abc from the drop down list then the output is "Second row".
please help me

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Sep. 2013
Have each listbox's callback call the same function, say GetColumnD() or whatever. Then in there, (untested code)
function itemFromColumnD = GetColumnD(handles, excelTable)
itemFromColumnD = []; % Initialize to null
% Get the item number that they selected.
selected1 = get(handles.listbox1, 'value')
selected2 = get(handles.listbox2, 'value')
selected3 = get(handles.listbox3, 'value')
% Get the contents (optional - just FYI in case you want to inspect)
items1 = get(handles.listbox1, 'String')
items2 = get(handles.listbox2, 'String')
items3 = get(handles.listbox3, 'String')
% Get the selected item (optional - just FYI in case you want to inspect)
selectedItem1 = items1{selected1};
selectedItem2 = items1{selected2};
selectedItem3 = items1{selected3};
% Now compare
if selected1 == selected2 && selected1 == selected3
% All indexes are the same so extract column D at that row.
itemFromColumnD = excelTable{selected1, 4};
end
Of course you need to make this more robust to handle things like selected is empty because they didn't have anything selected, use try/catch, etc.

Weitere Antworten (0)

Kategorien

Mehr zu Data Export to MATLAB 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!

Translated by