compare 3 column values and display the 4th column value as output
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Image Analyst
2013-9-11
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Export to MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!