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 件のコメント

Arsalan Khurshid
Arsalan Khurshid 2019 年 1 月 4 日
thanks madhan! but these are not my function inputs this is data i need from workspace my function inputs are x1,x2,x3.
Walter Roberson
Walter Roberson 2019 年 1 月 4 日
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.
Arsalan Khurshid
Arsalan Khurshid 2019 年 1 月 8 日
????
Stephen23
Stephen23 2019 年 1 月 8 日
"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?
Arsalan Khurshid
Arsalan Khurshid 2019 年 1 月 8 日
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!
madhan ravi
madhan ravi 2019 年 1 月 8 日
Anytime :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by