I want to save variables from a nested function into the parent function workspace so that I can use these variables again in another nested function. How do I do this?
Mostrar comentarios más antiguos
parent function ...
%user input numbers that go into BeamReactions
BeamReactions(BeamLength,BeamMass,Load,LoadX,LoadAngle)
%this is the function that I want to use answers from BeamReactions in
BeamLoadPlot(BeamLength,BeamWeightN,BeamWeightN_X,Load,LoadX,LoadAngle,FA_Y,FB_X,FB_Y)
Respuestas (3)
Walter Roberson
el 23 de Mzo. de 2018
0 votos
Don't do that. Instead, inside the parent function but before the definition of either nested function, assign some value to the variables, even if just []. That tells MATLAB that the variable is to be shared.
1 comentario
Julia Hambright
el 23 de Mzo. de 2018
Stephen23
el 23 de Mzo. de 2018
The whole point of nested functions is that you don't have to pass data as input/output arguments. All you need to do is define those variables in the workspace of the main function, and then all of the nested functions can access them:
function val = mymain()
val = [];
mynest()
function mynest()
val = 2;
end
end
Try calling it and see what the output is.
1 comentario
Julia Hambright
el 23 de Mzo. de 2018
Selin Ertunan
el 1 de Dic. de 2022
0 votos
hello, what exactly do we need to write inside the parentheses? When I write the code like this, I can see the nested variables, but still cannot save them as files.
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!