Using a GUI with Matlab

1 次查看(过去 30 天)
Hi everybody, i'm just trying to create a GUI with MATLAB but i have a problem with the variable. This is my code :
if true
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
a = get(handles.popupmenu2,'value')
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (a == 1)
plot(sin(0:.1:10));
end
But MATLAB answered me
if true
Undefined function or variable 'a'.
Error in fit>pushbutton1_Callback (line 269)
if (a == 1)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in fit (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)fit('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
end
Any ideas ?
Many thanks :)

采纳的回答

Stalin Samuel
Stalin Samuel 2016-4-1
编辑:Stalin Samuel 2016-4-1
Define 'a' as global variable . (Create a global variable in a GUI)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by