Opening a Figure from a Function – Not enough input arguments
Hello Reader! Basically, I am writing code that opens a figure with a button to be pressed on it, I want this button to open a figure saved in another file (same folder of course) as a function because this will keep the code tidy as a make more buttons/functions. I dont think figures works well on this online version of MATLAB.
Hello here is the function:
% Saved as flow_measurement
function flow_measurement(halfscreensizecentre,figurecolour)
figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider – Flow Measurement’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
end
Hello, here is part of my code:
screensize = get(groot,’ScreenSize’) ;
halfscreensizecentre = [(screensize(1,[3,4])/4),(screensize(1,[3 4]))/2] ;
figurecolour = [230/255 230/255 230/255] ;
figure1 = figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
buttoncolor = [0 64/255 115/255] ;
textcolor = [1 1 1] ;
toprowbuttonheight = 1 – 0.35 ;
toprowtextheight = toprowbuttonheight + 0.21 ;
flowmeasurementbutton = uicontrol(‘Style’,’pushbutton’,’Units’,’normalized’,’Position’,[.125/2,toprowbuttonheight,.25,.25],’BackgroundColor’,buttoncolor …
,’Callback’,@buttonfunction,’UserData’,’1′) ; % Creates a pushbutton
% Callback assigns button press to function following @
% UserData makes an output of 1
textonflowmeasurementbutton = uicontrol(‘Style’,’text’,’Units’,’normalized’,’Position’,[0.125/2+0.005,toprowtextheight,0.24,0.03] …
,’String’,’Flow Measurement’,’BackgroundColor’,buttoncolor,’ForegroundColor’,textcolor …
,’FontWeight’,’bold’,’FontSize’,7) ;
function buttonfunction(object, ~, halfscreensizecentre,figurecolour) % function returns two outputs, object & event, event is not used so is denoted by ~
object.UserData ; % Finds out what UserData is, which is determined by which button is pressed.
if strcmpi(object.UserData,’1′) % strcmp is case-insensitive string compare
disp (‘Flow Measurement’)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour} % ERROR ON THIS LINE
else
disp(‘How did we get here?’)
end
end
I run the code press the button a recieve the following error message:
Not enough input arguments.
Error in Year_2_Applied_Thermofluids_Calculator>buttonfunction (line 48)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour}
Error while evaluating UIControl Callback.
Any advice on how to fix my code and achieve my desired outcome? Thank you for your time.Hello Reader! Basically, I am writing code that opens a figure with a button to be pressed on it, I want this button to open a figure saved in another file (same folder of course) as a function because this will keep the code tidy as a make more buttons/functions. I dont think figures works well on this online version of MATLAB.
Hello here is the function:
% Saved as flow_measurement
function flow_measurement(halfscreensizecentre,figurecolour)
figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider – Flow Measurement’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
end
Hello, here is part of my code:
screensize = get(groot,’ScreenSize’) ;
halfscreensizecentre = [(screensize(1,[3,4])/4),(screensize(1,[3 4]))/2] ;
figurecolour = [230/255 230/255 230/255] ;
figure1 = figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
buttoncolor = [0 64/255 115/255] ;
textcolor = [1 1 1] ;
toprowbuttonheight = 1 – 0.35 ;
toprowtextheight = toprowbuttonheight + 0.21 ;
flowmeasurementbutton = uicontrol(‘Style’,’pushbutton’,’Units’,’normalized’,’Position’,[.125/2,toprowbuttonheight,.25,.25],’BackgroundColor’,buttoncolor …
,’Callback’,@buttonfunction,’UserData’,’1′) ; % Creates a pushbutton
% Callback assigns button press to function following @
% UserData makes an output of 1
textonflowmeasurementbutton = uicontrol(‘Style’,’text’,’Units’,’normalized’,’Position’,[0.125/2+0.005,toprowtextheight,0.24,0.03] …
,’String’,’Flow Measurement’,’BackgroundColor’,buttoncolor,’ForegroundColor’,textcolor …
,’FontWeight’,’bold’,’FontSize’,7) ;
function buttonfunction(object, ~, halfscreensizecentre,figurecolour) % function returns two outputs, object & event, event is not used so is denoted by ~
object.UserData ; % Finds out what UserData is, which is determined by which button is pressed.
if strcmpi(object.UserData,’1′) % strcmp is case-insensitive string compare
disp (‘Flow Measurement’)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour} % ERROR ON THIS LINE
else
disp(‘How did we get here?’)
end
end
I run the code press the button a recieve the following error message:
Not enough input arguments.
Error in Year_2_Applied_Thermofluids_Calculator>buttonfunction (line 48)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour}
Error while evaluating UIControl Callback.
Any advice on how to fix my code and achieve my desired outcome? Thank you for your time. Hello Reader! Basically, I am writing code that opens a figure with a button to be pressed on it, I want this button to open a figure saved in another file (same folder of course) as a function because this will keep the code tidy as a make more buttons/functions. I dont think figures works well on this online version of MATLAB.
Hello here is the function:
% Saved as flow_measurement
function flow_measurement(halfscreensizecentre,figurecolour)
figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider – Flow Measurement’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
end
Hello, here is part of my code:
screensize = get(groot,’ScreenSize’) ;
halfscreensizecentre = [(screensize(1,[3,4])/4),(screensize(1,[3 4]))/2] ;
figurecolour = [230/255 230/255 230/255] ;
figure1 = figure(‘Name’,’Applied Thermofluids Calculator by Philip Schneider’,’Position’,halfscreensizecentre,’Color’,…
figurecolour,’MenuBar’,’none’,’NumberTitle’,’off’)
buttoncolor = [0 64/255 115/255] ;
textcolor = [1 1 1] ;
toprowbuttonheight = 1 – 0.35 ;
toprowtextheight = toprowbuttonheight + 0.21 ;
flowmeasurementbutton = uicontrol(‘Style’,’pushbutton’,’Units’,’normalized’,’Position’,[.125/2,toprowbuttonheight,.25,.25],’BackgroundColor’,buttoncolor …
,’Callback’,@buttonfunction,’UserData’,’1′) ; % Creates a pushbutton
% Callback assigns button press to function following @
% UserData makes an output of 1
textonflowmeasurementbutton = uicontrol(‘Style’,’text’,’Units’,’normalized’,’Position’,[0.125/2+0.005,toprowtextheight,0.24,0.03] …
,’String’,’Flow Measurement’,’BackgroundColor’,buttoncolor,’ForegroundColor’,textcolor …
,’FontWeight’,’bold’,’FontSize’,7) ;
function buttonfunction(object, ~, halfscreensizecentre,figurecolour) % function returns two outputs, object & event, event is not used so is denoted by ~
object.UserData ; % Finds out what UserData is, which is determined by which button is pressed.
if strcmpi(object.UserData,’1′) % strcmp is case-insensitive string compare
disp (‘Flow Measurement’)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour} % ERROR ON THIS LINE
else
disp(‘How did we get here?’)
end
end
I run the code press the button a recieve the following error message:
Not enough input arguments.
Error in Year_2_Applied_Thermofluids_Calculator>buttonfunction (line 48)
flowmeasurementfigure.Callback = {@flow_measurement,halfscreensizecentre,figurecolour}
Error while evaluating UIControl Callback.
Any advice on how to fix my code and achieve my desired outcome? Thank you for your time. not enough input arguments, figure, function MATLAB Answers — New Questions