Need help with a school treeplot "homework".

Build a GUI application for the syntaxes:
treeplot (p)
treeplot (p, nodeSpec, edgeSpec)
It is required in the graphical interface to find:
· A menu called 'Sintaxe' and 2 submenus that allows to select the syntax of the desired function
· An edit box for reading p
· Graphical objects to read input arguments nodeSpec, edgeSpec
· A button called 'Rezultat' that, when enabled, displays graphical representations of functions on an axis object.

5 Comments

So far i got this:
function varargout = untitled(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function sintaxe_Callback(hObject, eventdata, handles)
function functia1_Callback(hObject, eventdata, handles)
treeplot([0 1 1]);
function functia2_Callback(hObject, eventdata, handles)
treeplot([0 1 1 1]);
uicontrol should be helpful here. Those callbacks don't do anything by themselves. The code you posted looks like a cleaned up version of the default output of GUIDE. GUIDE also has an option to generate the code for the .fig.
Managed to get this so far, however i wish to clean up a bit the code and also to rename the Menu from treeplot to Sintaxe and i can't find this option :( Any thoughts? Thanks a lot!
function varargout = ProiectRamon(varargin)
% My Project on Work
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ProiectRamon_OpeningFcn, ...
'gui_OutputFcn', @ProiectRamon_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
function ProiectRamon_OpeningFcn(hObject, eventdata, handles, varargin)
global aux;
aux = 0;
handles.output = hObject;
guidata(hObject, handles);
function varargout = ProiectRamon_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
p = get(handles.edit1,'String'); p = str2num(p);
nodeSpec = get(handles.edit2,'String');
edgeSpec = get(handles.edit3,'String');
global aux;
if aux == 1
treeplot(p);
elseif aux == 2
treeplot(p,nodeSpec,edgeSpec);
end
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% % --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
global aux;
aux = 1;
% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
global aux;
aux = 2;
Why are you using a global, instead of saving it to a field in your guidata? And what do you mean with renaming the menu? Do you want to rename the function?
%replace
global aux;
aux = 0;
%with
handles.aux=0;
guidata(hObject,handles)
%and in pushbutton1_Callback, replace
global aux;
%with
aux=handles.aux;
Thanks Rik. When i run this, i get a fig file and i am able to run the submenus treeplot (p) and treeplot (p, nodeSpec, edgeSpec), but the main menu is called treeplot instead of Sintaxe like it was requested in the exercise content. Anyway thanks a lot for clearing out the global aux.

Sign in to comment.

Answers (0)

Categories

Asked:

on 31 Jan 2018

Commented:

on 19 Feb 2018

Community Treasure Hunt

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

Start Hunting!