フィルターのクリア

How to collect a new variable each time a function runs and save it into an array

1 回表示 (過去 30 日間)
Hi, I have a program that is collecting a variable each time it is run through the function (every minute) and it collects a variable called 'VWAP'.
How do I save this data so next time the function runs it will save the new value of the variable in an array so all the values can saved for analysis later?
I was looking at mlock, but I am not sure how to use that to build an array.
Any assistance even directional is appreciated. thanks
Allan
function processContracts(contracts, params)
datavwap = IQML('quotes','Symbol','ACB','Fields',{'Bid','Ask','Last','VWAP','time'});
end
  2 件のコメント
Rik
Rik 2020 年 11 月 30 日
A persistent variable would be a good start. You may also want to consider using a class.
Allan Munro
Allan Munro 2020 年 12 月 3 日
Thanks for the help!!! Very Informative!

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

採用された回答

Raynier Suresh
Raynier Suresh 2020 年 12 月 3 日
This can be done by using either “Persistent” or “Global” variable.
Refer the below code:
function myFun(x)
persistent n;
n = [n x]
end
myFun(10)
n =
10
myFun(12)
n =
10 12
If in case its necessary to move the variable from the function to base workspace you can use “assignin
Refer the below links for more information:
  1 件のコメント
Rik
Rik 2020 年 12 月 3 日
Both global and assignin should be considered hacks and are rarely if ever needed.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by