2014-11-06 38 views
0

我是Matlab新手。現在的任務是在GUI中顯示標題,並在腳本運行時不斷更新標題。如何在Matlab GUI中傳遞call_backs之間的值

我創建了一個名爲GUI界面,所以在主腳本是

Interface(title); 
在GUI

function Interface_OpeningFcn(hObject, eventdata, handles, varargin) 
% This function has no output args, see OutputFcn. 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% varargin command line arguments to Interface (see VARARGIN) 

% Choose default command line output for Interface 
handles.output = hObject; 
handles.title = varargin{1}; 
% Update handles structure 
guidata(hObject, handles); 

我通過標題handles.title

,在格蘭靜態文本的call_back功能:

title =get(handles.title,'Value'); 
set(handles.text1,'String',title'); 

它不斷給我的錯誤信息說,我讀「試圖引用非結構陣列的領域。」

感謝您的幫助

+1

'set(handles.text1,'String',title');'在'title'後面有'''不屬於那裏。 – 0xMB 2014-11-06 11:14:17

回答

0

我想你只需要擁有:

set(handles.text1,'String',handles.title); % assumes the title input (and therefore handles.title) is a string 
guidata(hObject,handles); 

只要確保爲靜態文本回調函數傳遞handles作爲輸入。另外,你沒有說如何定義handles.text1,我假設你在嘗試設置String屬性之前已經定義了它。