Function RunButtonPushed(app, event) nothing happens when button is pushed.

% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ResolutioninnmEditField matlab.ui.control.NumericEditField
ResolutioninnmEditFieldLabel matlab.ui.control.Label
RunButton matlab.ui.control.Button
centeredwavelengthnmEditField matlab.ui.control.NumericEditField
centeredwavelengthnmEditFieldLabel matlab.ui.control.Label
Resincm1EditField matlab.ui.control.NumericEditField
Resincm1EditFieldLabel matlab.ui.control.Label
end
methods (Access = private)
% Button pushed function: RunButton
function RunButtonPushed(app, event)
ScriptPath = pwd; % Find current path to script as start point
% converts given spectral resolution to theoretical resolution limit
% ignoring pixel size
% initializing variables
wavenumsp = app.centeredwavelengthnmEditField;
wavelengthcenter = app.Resincm1EditField; % user input for centeral wave in um
wavenumcenter = 1/(wavelengthcenter*10000); % converting wavelength to wavenumber
delwave = wavenumcenter - wavenumsp; % finding delta of wavenumbers
Result = ((1/delwave)*1E7)-wavelengthcenter*1000; % Result in nm
app.ResolutioninnmEditField.Value = wavenumsp;
end
end
This is the code above, it's a very simple function I just need it to display the calculated value nothing happens when I push the button, the code runs fine just the button doesn't work.

 Accepted Answer

function RunButtonPushed(app, event)
% ScriptPath = pwd; % Find current path to script as start point
% converts given spectral resolution to theoretical resolution limit
% ignoring pixel size
% initializing variables
% wavenumsp = app.centeredwavelengthnmEditField;
wavenumsp = app.centeredwavelengthnmEditField.Value;
% wavelengthcenter = app.Resincm1EditField; % user input for centeral wave in um
wavelengthcenter = app.Resincm1EditField.Value; % user input for centeral wave in um
wavenumcenter = 1/(wavelengthcenter*10000); % converting wavelength to wavenumber
delwave = wavenumcenter - wavenumsp; % finding delta of wavenumbers
Result = ((1/delwave)*1E7)-wavelengthcenter*1000; % Result in nm
% app.ResolutioninnmEditField.Value = wavenumsp;
app.ResolutioninnmEditField.Value = Result; % Use the Result just calculated?
end

6 Comments

I tried this, and it still did not work. When I hit the run button nothing populates the text field.
Please post the current relevant code, along with any error messages in the command window.
function RunButtonPushed(app, event)
% ScriptPath = pwd; % Find current path to script as start point
% converts given spectral resolution to theoretical resolution limit
% ignoring pixel size
% initializing variables
% wavenumsp = app.centeredwavelengthnmEditField;
wavenumsp = app.centeredwavelengthnmEditField.Value;
% wavelengthcenter = app.Resincm1EditField; % user input for centeral wave in um
wavelengthcenter = app.Resincm1EditField.Value; % user input for centeral wave in um
wavenumcenter = 1/(wavelengthcenter*10000); % converting wavelength to wavenumber
delwave = wavenumcenter - wavenumsp; % finding delta of wavenumbers
Result = ((1/delwave)*1E7)-wavelengthcenter*1000; % Result in nm
% app.ResolutioninnmEditField.Value = wavenumsp;
app.ResolutioninnmEditField.Value = Result; % Use the Result just calculated?
end
There are no errors, the app runs fine it seems the function just never runs, I hit the run button and nothing happened.
Is the button's callback set up properly? That is to say, can you verify that the ButtonPushedFcn of app.RunButton is set to the function RunButtonPushed in AppDesigner?
Ahh that would be why, I was just typing the code including the function I did not know you had to select call back thank you!
You're welcome! Glad you got that sorted out!

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Tags

Asked:

on 11 Jan 2023

Commented:

on 11 Jan 2023

Community Treasure Hunt

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

Start Hunting!