Compare two column values and display the third column value from the excel based on list box input.

조회 수: 2 (최근 30일)
i have a excel sheet which is having 3 columns each column is having the student information.
1st and 2nd columns are having the semester-I and semester-II status respectively like "pass", "Fail", "Distinction", "first", "second", "third class"..etc
In my GUI, i have two list box which is for sem-I and Sem-II marks. if i select any input from the both list box then it has to compare with the excel sheet row values.
once both the list box inputs are found in the excel sheet, then it has to display the 3rd column value as the output
for example
if i select "distinction" from 1st list box and "Fail" from 2nd listbox then it has to show the corresponding value from the 3rd column...

답변 (1개)

Vishal Rane
Vishal Rane 2013년 9월 23일
If you need to read data from excel and display it in the listbox:
- use xlsread to read data from the specific cells
- assign the data to the listboxes using set()
  댓글 수: 3
Vishal Rane
Vishal Rane 2013년 9월 23일
All u need now is the selected values from the list boxes.
get(listbox_handle,'Value')
gives index of the selected element from the list.
Mary
Mary 2013년 9월 24일
편집: Mary 2013년 9월 24일
CODE:
function listbox1 _Callback(hObject, eventdata, handles)
index_selected = get(hObject,'Value');
list = get(hObject,'String');
item_selected = list{index_selected}; % Convert from cell array % to string
disp(item_selected);
function listbox2 _Callback(hObject, eventdata, handles)
index_selected = get(hObject,'Value');
list = get(hObject,'String');
item_selected2 = list{index_selected};
disp(item_selected2);
function OK_PUSHBUTTON _Callback(hObject, eventdata, handles)
function itemFromColumnC = GetColumnC(handles, textdata);
itemFromColumnC = []; % Initialize to null
% Get the item number that they selected.
selected1 = get(handles.item_selected1, 'value');
selected2 = get(handles.item_selected2, 'value');
% Get the contents items1 = get(handles.item_selected2, 'String');
items2 = get(handles.item_selected2, 'String'); % Get the selected item
selectedItem1 = items1{selected1};
selectedItem2 = items2{selected2};
% Now compare if selected1 == selected2
itemFromColumnC = textdata{selected1, 3};
end message = sprintf('%s',itemFromColumnC);
uiwait(msgbox(message));
If I select pass from listbox1 and fail from listbox2 then it has to display the D Grade as an output (See the 7th row in excel sheet).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by