how to access a variable from workspace to be used in a function?

hi! i am facing this problem while creating a function
function y=abc(x1,x2,x3)
wmeasured=wmeas.data; %time series saved in workspace
pmeasured=pmeas.data; %time series saved in workspace
.
.
.
.
y=.........
end
it does not find the timeseries wmeas & pmeas. how can i load these values?
kindly help!
thanks!

 Réponse acceptée

madhan ravi
madhan ravi le 4 Jan 2019
Modifié(e) : madhan ravi le 4 Jan 2019
Parameterize your function(link)- please read the link (pass those variables as function inputs) and call them.

6 commentaires

thanks madhan! but these are not my function inputs this is data i need from workspace my function inputs are x1,x2,x3.
and the solution is to not program that way. pass those variables in through as many layers as you need to reach the place they are needed.
"how can i load these values?"
Exactly as madhan ravi wrote, you should parameterize your function. Either:
  1. pass all required variables as input arguments, and then use an anonymous function to parameterize it, or
  2. use a nested function.
Have you tried either of these? Is there a good reaon why they will not work?
this worked for me
function y=abc(x1,x2,x3,wmeas,pmeas)
wmeasured=wmeas; % array saved in workspace
pmeasured=pmeas; % array saved in workspace
.
.
.
.
y=.........
end
thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by