Using GUIDE trying to plot a figure in GUI axes

20 Ansichten (letzte 30 Tage)
saurosaum
saurosaum am 3 Aug. 2017
Kommentiert: Venkat Ta am 11 Jan. 2019
I have a code that I want to make an app of using GUIDE. The code takes a mat file as an input, makes some calculations and then plots two figures. When I implement this in GUIDE, I am able to get the first two steps alright. However, when I try to plot in the guide axes, I get the error: Reference to non-existent field 'axes1'. I am also attaching the fig file for the GUI. Thanks a ton for your help, Matlab community!
Here is the code:
function varargout = Disoplotter(varargin)
%DISOPLOTTER MATLAB code file for Disoplotter.fig
% DISOPLOTTER, by itself, creates a new DISOPLOTTER or raises the existing
% singleton*.
%
% H = DISOPLOTTER returns the handle to a new DISOPLOTTER or the handle to
% the existing singleton*.
%
% DISOPLOTTER('Property','Value',...) creates a new DISOPLOTTER using the
% given property value pairs. Unrecognized properties are passed via
% varargin to Disoplotter_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% DISOPLOTTER('CALLBACK') and DISOPLOTTER('CALLBACK',hObject,...) call the
% local function named CALLBACK in DISOPLOTTER.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Disoplotter
% Last Modified by GUIDE v2.5 03-Aug-2017 15:09:34
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Disoplotter_OpeningFcn, ...
'gui_OutputFcn', @Disoplotter_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Disoplotter is made visible.
function Disoplotter_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for Disoplotter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
plot(handles.axes1,[1 2 3],[1 2 3])
% UIWAIT makes Disoplotter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Disoplotter_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton2.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,~]=uigetfile('*.mat','Get File')
handles = load(FileName)
guidata(hObject,handles)
% --- Executes on button press in pushbutton1.
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
handles.geneName = get(hObject,'String');
guidata(hObject,handles);
disp(handles.geneName);
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
function pushbutton2_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)
userInput = handles.geneName;
disp(userInput)
%disp(length(handles.proteome_1_end))
%Code that does a bunch of calculations here
%Code that does a bunch of calculations here
%Code that does a bunch of calculations here
%Code that does a bunch of calculations here
%%This is where I want to plot in axes 1
[countsSW, binCentersSW] = hist(sort(swarmerYY),XX);
axes(handles.axes1);
bar(binCentersSw, countsSw, 'BarWidth', 1);

Akzeptierte Antwort

Julian Rosker
Julian Rosker am 3 Aug. 2017
Rather than using:
handles.axes1
you can use:
axesHandle = findobj('Tag', 'tagForYourAxes');
plot(axesHandle,[1 2 3],[1 2 3])
...
axes(findobj('Tag', 'tagForYourAxes')); %At the 2nd place in your code where you use 'handles.axes1'
Just change 'tagForYourAxes' to be whatever you set the figure's tag to be when you created the GUI with GUIDE and use that snippet . This should work, but I could not fully test it since I do not have the .fig file.
  3 Kommentare
Alexander Saad-Falcon
Alexander Saad-Falcon am 7 Jun. 2018
Bearbeitet: Alexander Saad-Falcon am 7 Jun. 2018
LOL hi Julian this helped a lot
Venkat Ta
Venkat Ta am 11 Jan. 2019
it works but not for plot. it works for semilogx ...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by