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

2 visualizzazioni (ultimi 30 giorni)
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...

Risposte (1)

Vishal Rane
Vishal Rane il 23 Set 2013
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 Commenti
Vishal Rane
Vishal Rane il 23 Set 2013
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 il 24 Set 2013
Modificato: Mary il 24 Set 2013
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).

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by