VAriables of a function inside a function

Good morning,
I am runnung iterative loop
loop(arg) where arg is a number to specify matlab how many times to run the loop(arg)
There are certain function inside the loop(arg) to run simulation and followed by convergence criteria inside a loop(arg)
My question is i need to extract global variable 'rxf' assigned and present inside a loop(arg) to be used in a function where loop(arg) executed inside that function. But i observe error Unrecognized function or variable 'rxf'.
Any idea how to resolve this issue.
Thank you in advance.

6 个评论

Show us your code and specify the error with line number.
The code is very big. I can't put it here. But i can show syntax of code:
F_target=40;
Targetfn =@(x1) (sim_results(x1)-F_obj)^2
Optimal_YM = fminbnd(Targetfn,1000,1800);
function [F_sim]=sim_results(x1)
initial_input(x1)
loop(1); -----> from here i can get rxf which i can use i did previously for certain operation outside the loop but when i put loop here and try to extract rxf infomation to the below line its showng error '"Unrecognized function or variable 'rxf'."
F_sim = rxf(10,:);
end
More over the rxf variable is showing the wrokspace and i can do operations with rxf but when i use rxf inside another function to do operations its showning the above error "Unrecognized function or variable 'rxf'.".
For some clarification after loop execution inside that function function [F_sim]=sim_results(x1)
rxf (global variable) output can be seen in workspace but next line F_sim = rxf(10,:); when executed its showing error "Unrecognized function or variable 'rxf'.".
Problem resolved. Thank you for your response.
i need to define again global variable inside the function which i used in loop(arg) ---> rxf it seems now it is not showing any error.
FWIW, calling a function in an anonymous function doesn't imply the same variable scoping rules that apply to functions with nested scopes.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by