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 件のコメント

Bradley
Bradley 2023 年 1 月 11 日
I tried this, and it still did not work. When I hit the run button nothing populates the text field.
Voss
Voss 2023 年 1 月 11 日
Please post the current relevant code, along with any error messages in the command window.
Bradley
Bradley 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
There are no errors, the app runs fine it seems the function just never runs, I hit the run button and nothing happened.
Voss
Voss 2023 年 1 月 11 日
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?
Bradley
Bradley 2023 年 1 月 11 日
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!
Voss
Voss 2023 年 1 月 11 日
You're welcome! Glad you got that sorted out!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop 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