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.

 채택된 답변

Voss
Voss 2023년 1월 11일
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

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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Programmatically에 대해 자세히 알아보기

태그

질문:

2023년 1월 11일

댓글:

2023년 1월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by