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!

 채택된 답변

madhan ravi
madhan ravi 2019년 1월 4일
편집: madhan ravi 2019년 1월 4일

1 개 추천

Parameterize your function(link)- please read the link (pass those variables as function inputs) and call them.

댓글 수: 6

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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series에 대해 자세히 알아보기

질문:

2019년 1월 4일

댓글:

2019년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by