- 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.
access data in App-Designer in nested function call
1 次查看(过去 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.
0 个评论
回答(1 个)
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:
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!
另请参阅
类别
在 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!