Clear Filters
Clear Filters

GUI Interface: Need advice on a few things

2 views (last 30 days)
A
A on 31 May 2015
Commented: A on 1 Jun 2015
Hello there,
I have the below test GUI .m file which takes three user inputs, outputs 1 value, and graphs a surface.
Here's where I need help:
1) Is there a way to remove/replace the matlab logo in the top left of the window of this GUI program?
2) Is there a way to make the blue textbox uneditable and still maintain its blue color? I tried disabling it, but that grays it out and I want to keep its blue color.
3) Is there a way to mark a point on the surface for the given user input values for X and Y? So I want to put a red dot at the X,Y from the user and have a tiny textbox next to it which says "X = this, Y = this, Z = this".
I hope I am not asking for too much.
Thank you
function varargout = TestInterface(varargin)
% TESTINTERFACE Application M-file for TestInterface.fig
% TESTINTERFACE, by itself, creates a new TESTINTERFACE or raises the existing
% singleton*.
%
% H = TESTINTERFACE returns the handle to a new TESTINTERFACE or the handle to
% the existing singleton*.
%
% TESTINTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTINTERFACE.M with the given input arguments.
%
% TESTINTERFACE('Property','Value',...) creates a new TESTINTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before two_axes_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TestInterface_OpeningFcn via varargin.
%
% *See GUI Options - GUI allows only one instance to run (singleton).
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help TestInterface
% Copyright 2001-2006 The MathWorks, Inc.
% Last Modified by GUIDE v2.5 31-May-2015 17:20:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TestInterface_OpeningFcn, ...
'gui_OutputFcn', @TestInterface_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 TestInterface is made visible.
function TestInterface_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 TestInterface (see VARARGIN)
% Choose default command line output for TestInterface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TestInterface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = TestInterface_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;
% --------------------------------------------------------------------
function plot_button_Callback(hObject, eventdata, handles, varargin)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(0,'DefaultFigureColor','White',...
'defaultaxesfontsize',8,...
'DefaultAxesFontname','Calibri',...
'DefaultTextFontName','Calibri')
x = [0:50];
y = [0:50];
% Get user input from GUI
f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
constant = str2double(get(handles.constant,'String'));
%Common Variables
Form1 = @(x,y)(2.*x+y+constant);
% Calculate data
TestFormula = @(x,y)(x - y.*constant);
[X1,Y1] = meshgrid(x,y);
Z1 = TestFormula(X1,Y1);
Z2 = TestFormula(f1,f2);
s1 = surf(X1,Y1,Z1);
% Create frequency plot in proper axes
set(handles.edit5,'String',round(Z2,2))
axis tight
camlight
lighting phong
shading interp
set(s1,'FaceColor',[0.70 0.85 1], 'edgecolor',[0 0 0.4],'meshstyle','both','linewidth',.15);
function f1_input_Callback(hObject, eventdata, handles)
% hObject handle to f1_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f1 field converts to a real number
f1 = str2double(get(hObject,'String'));
if isnan(f1) || ~isreal(f1)
% isdouble returns NaN for non-numbers and f1 cannot be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f1')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
function f2_input_Callback(hObject, eventdata, handles)
% hObject handle to f2_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f2 field converts to a real number
f2 = str2double(get(hObject,'String'));
if isnan(f2) ... % isdouble returns NaN for non-numbers
|| ~isreal(f2) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f2')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (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 edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 constant_Callback(hObject, eventdata, handles)
% hObject handle to constant (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 constant as text
% str2double(get(hObject,'String')) returns contents of constant as a double
constant = str2double(get(hObject,'String'));
if isnan(constant) ... % isdouble returns NaN for non-numbers
|| ~isreal(constant) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot constant')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
% --- Executes during object creation, after setting all properties.
function constant_CreateFcn(hObject, eventdata, handles)
% hObject handle to constant (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
% --- Executes when figure1 is resized.
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
  3 Comments
Jan
Jan on 1 Jun 2015
"I tried disabling it" is not unique. Please post the code, because it matters if you set 'Enable' to 'off' or to 'inactive'.
A
A on 1 Jun 2015
Sorry about that. I have fixed these issues. Thank you.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 1 Jun 2015
With regards to the Mathworks logo: No, it is a violation of license to replace the logo in an interactive MATLAB session. If you are compiling using MATLAB Compiler then deploytool has an option to put in a different image.
  1 Comment
A
A on 1 Jun 2015
Thank you. Is deploytool part of the MatLab compiler or is it something separate I need to download?

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!