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 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