Trying to create a callback function on App Designer.
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I can be considered as newbie for Matlab and am trying to create an application that calculates the nominal interest rate "i".
i = N*((T/P)^(1/(N*Y))) - N where
i = nominal interest rate
P = initial investment
T = future value
N = number of compounding periods per year
Y = number of years
The basic look of my application as following:

I want this application to execute the function that I gave above when you click the calculate button. In order to to that, I right click the calculate button and after that click callback then add the function up there. However, I do not know how to display it on the bottom field and I get an error when I click the calculate button as following, you can also see my callback function there: 

As a result, what is my mistake and what should I do to create this callback function properly and display its result on the "i" field?
Appreciated for your help.
0 个评论
回答(1 个)
Harshavardhan
2025-2-7
Hi @Burak Akin
I understand that you are attempting to compute and display the value of the variable "i”. This calculation is based on inputs received from four "NumericEditField" components. When a button is clicked, a formula is applied to these inputs to determine the value of "i”.
The problem is that the variables “app.p_val”, “app.t_val”, etc., are objects rather than numeric variables. To get the numeric value of these fields you can use the property “Value”. For more information on “NumericEditField” you can type the following line in a MATLAB command window.
doc NumericEditField
Moreover, to see the value of the result, the “NumericEditField” “i” needs to be modified.
The code with the changes is given below:
function cal_butButtonPushed(app, event)
P = app.p_val.Value; % getting the Value of P
T = app.t_val.Value; % getting the Value of T
N = app.n_val.Value; % getting the Value of N
Y = app.y_val.Value; % getting the Value of Y
app.i_val.Value = N*((T/P)^(1/(N*Y))) - N; %calculating and setting the value of i
end
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!