access data in App-Designer in nested function call

27 次查看(过去 30 天)
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,6:54
编辑:Aditya 2024-6-28,6:55
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,7:10
Hello Aditya, Thank you for your very quick answer. I will try you hints and keep you informed.
Claus

请先登录,再进行评论。

类别

Help CenterFile 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!

Translated by