access data in App-Designer in nested function call

1 回表示 (過去 30 日間)
Claus Schmidt
Claus Schmidt 2024 年 6 月 28 日
コメント済み: Claus Schmidt 2024 年 6 月 28 日
I have defined a variable cr as a public propertie and can refer to it within the program by usind app.cr. However I call a function withinh function
where I need to use the variable, but by running the programm I get an error message:
Unrecognized field name "cr".
app.TMG_solver( n, x, y, z, vx, vy, vz, bx, by, bz);
app.EarthOrbit;
app.OrbitMain;
What am I doing wrong.

回答 (1 件)

Aditya
Aditya 2024 年 6 月 28 日
編集済み: Aditya 2024 年 6 月 28 日
Hi Claus,
It looks like you're encountering an issue with accessing the cr property within a nested function call in MATLAB App Designer. In MATLAB, nested functions do not automatically have access to the properties of the app unless explicitly passed.
Based on the error that you have provided, your file structure should look like this for it to work properly:
properties (Access = public)
cr
end
methods (Access = private)
function ComputeButtonPushed(app, event)
app.OrbitMain();
end
function OrbitMain(app)
app.EarthOrbit();
end
function EarthOrbit(app)
% Access the cr property
disp(app.cr);
% Call another function without passing app explicitly
app.TMG_solver(n, x, y, z, vx, vy, vz, bx, by, bz);
end
function TMG_solver(app, n, x, y, z, vx, vy, vz, bx, by, bz)
% Access the cr property
disp(app.cr);
end
end
Additional Suggestions
1) Clarify the Scope of cr: Ensure that 'cr; is defined as a public property so it can be accessed throughout the app.
2) Debugging Steps:
  • Print Statements: Add print statements to verify that the functions are being called as expected.
  • Breakpoint: Set breakpoints in the MATLAB editor to inspect the state of the app object and its properties.
If you are having the same file structure and still facing the issue, could you please provide more details to reproduce the issue? You can share the functions that are being used within the file which are leading to this error.
I hope this helps!
  1 件のコメント
Claus Schmidt
Claus Schmidt 2024 年 6 月 28 日
Hello Aditya, Thank you for your very quick answer. I will try you hints and keep you informed.
Claus

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by