2013-09-30 71 views
-1
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); 
textdata=xlsread('stringipdata.xlsx'); 
GetColumnC(handles, textdata); 




function listbox2_Callback(hObject, eventdata, handles) 
index_selected = get(hObject,'Value'); 
list = get(hObject,'String'); 
item_selected2 = list{index_selected}; % Convert from cell array 
             % to string 
disp(item_selected2); 
textdata=xlsread('stringipdata.xlsx'); 
GetColumnC(handles, textdata); 




function itemFromColumnC = GetColumnC(handles, textdata) 


itemFromColumnC = []; % Initialize to null 

% Get the item number that they selected. 
selected1 = get(handles.listbox1, 'value'); 
selected2 = get(handles.listbox2, 'value'); 


% Get the contents (optional - just FYI in case you want to inspect) 
items1 = get(handles.listbox1, 'String'); 
items2 = get(handles.listbox2, 'String'); 
% Get the selected item (optional - just FYI in case you want to inspect) 
selectedItem1 = items1{selected1}; 
selectedItem2 = items2{selected2}; 


% Now compare 
if selected1 == selected2 
    % All indexes are the same so extract column C at that row. 

itemFromColumnC = textdata{selected1, 3}; 
    disp(itemFromColumnC); 

end 

錯誤是:錯誤在我的代碼......請幫我解決

???來自非單元格數組對象的單元格內容引用。

錯誤在==> stringdata> GetColumnC在188 itemFromColumnC = textdata {selected1,3};

  • 細胞值是字符串
  • 我想顯示的第三列單元值作爲 輸出。

回答

2

xlsread的第一個輸出是一個正常(雙數)數組。第三個輸出是一個包含xls所有內容的單元格數組。你應該這樣稱呼它:

[t1, t2, textdata] = xlsread('stringipdata.xlsx'); % or replace t1 and t2 by ~ 
+0

很多非常感謝你....我從很多天試圖這個......非常感謝 – user2829984