I am having problems with GUI
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to run the program BasicScreen that I have written and which ran until I tried to embed it in a loop. I have taken it out of the loop and given it the information that it needs. However, running it gives the error message
Error: File: BasicScreen.m Line: 42 Column: 25
Brace indexing into the result of a function call is not supported. Assign the result of
'varargin' to a variable first, then brace index into it.
I MUST ADMIT THAT I HAVE NOT GOT A CLUE WHAT THIS MEANS. HOW DO I GET RID OF THE ERROR? THE CODE IS BELOW, I CAANNOT ATTACH THE GUI. I HAVE PUT IN BOLD THE LINE WITH THE ERROR MESSAGE.
function varargout = BasicScreen
ProbR=0.6;
ProbY=0.4;
ExR=1;
ExY=1;
global x0,y0global ProbR ProbY ExR ExY
global ProbR ProbY ExR ExY
% BASICSCREEN MATLAB code for BasicScreen.fig
% BASICSCREEN, by itself, creates a new BASICSCREEN or raises the existing
% singleton*.
%
% H = BASICSCREEN returns the handle to a new BASICSCREEN or the handle to
% the existing singleton*.
%
% BASICSCREEN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BASICSCREEN.M with the given input arguments.
%
% BASICSCREEN('Property','Value',...) creates a new BASICSCREEN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before BasicScreen_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to BasicScreen_OpeningFcn via varargin.
%
% *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 BasicScreen
% Last Modified by GUIDE v2.5 23-Apr-2024 11:15:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BasicScreen_OpeningFcn, ...
'gui_OutputFcn', @BasicScreen_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin > 1 && 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 BasicScreen is made visible.
function BasicScreen_OpeningFcn(hObject, eventdata, handles, varargin)
global x0 y0
global ProbR ProbY ExR ExY
disp("in opening")
x0
y0
probR
probY
% Create the RedBox and YellowBox rectangles
% handles.RedBox = rectangle('Position', [x0, y0, probR, 50]);
% handles.YellowBox = rectangle('Position', [x0 + probR, y0, probY, 50]);
% Set the axis limits
% axis([0 100 0 100]);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes BasicScreen wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = BasicScreen_OutputFcn(hObject, eventdata, handles)
global x0 y0
global ProbR ProbY ExR ExY
% 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 edit1_Callback(hObject, eventdata, handles)
global x0 y0
global ProbR ProbY ExR ExY
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
global x0 y0
global ProbR ProbY ExR ExY
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
axis([0 100 0 100]);
% 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 on slider movement.
function slider1_Callback(hObject, eventdata, handles)
global x0 y0
global ProbR ProbY ExR ExY
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
disp("in slider")
% probR
% probY
val1=get(handles.slider1,'value');
val=num2str(val1);
set(handles.edit1,'string',val);
x0=90;
y0=24;
disp("clicking on the slider")
% x0
% y0
% probR
% probY
% disp("val then val1")
% val
% val1
axis([0 100 0 100]);
set(handles.RedBox, 'Position', [x0, y0, probR, val1]);
set(handles.YellowBox, 'Position', [x0 + probR, y0, probY, 100 - val1]);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
AND HERE IS THE GUI:
0 commentaires
Réponses (1)
Voss
le 23 Avr 2024
Modifié(e) : Voss
le 23 Avr 2024
Change the main BasicScreen function back to how it was (in particular, it appears you inadvertently removed the text "(varargin)" from the function definition; in general, you should never edit the main function of a GUIDE m-file):
function varargout = BasicScreen(varargin)
% BASICSCREEN MATLAB code for BasicScreen.fig
% BASICSCREEN, by itself, creates a new BASICSCREEN or raises the existing
% singleton*.
%
% H = BASICSCREEN returns the handle to a new BASICSCREEN or the handle to
% the existing singleton*.
%
% BASICSCREEN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BASICSCREEN.M with the given input arguments.
%
% BASICSCREEN('Property','Value',...) creates a new BASICSCREEN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before BasicScreen_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to BasicScreen_OpeningFcn via varargin.
%
% *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 BasicScreen
% Last Modified by GUIDE v2.5 23-Apr-2024 11:15:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BasicScreen_OpeningFcn, ...
'gui_OutputFcn', @BasicScreen_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin > 1 && 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
And put all your global declarations and other initialization code in BasicScreen_OpeningFcn.
% --- Executes just before BasicScreen is made visible.
function BasicScreen_OpeningFcn(hObject, eventdata, handles, varargin)
global x0 y0
global ProbR ProbY ExR ExY
disp("in opening")
ProbR=0.6;
ProbY=0.4;
ExR=1;
ExY=1;
x0
y0
probR
probY
% Create the RedBox and YellowBox rectangles
% handles.RedBox = rectangle('Position', [x0, y0, probR, 50]);
% handles.YellowBox = rectangle('Position', [x0 + probR, y0, probY, 50]);
% Set the axis limits
% axis([0 100 0 100]);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes BasicScreen wait for user response (see UIRESUME)
% uiwait(handles.figure1);
0 commentaires
Voir également
Catégories
En savoir plus sur Digital Filtering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!