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!