save workspace variable dynamically

2 ビュー (過去 30 日間)
DavyJonesLocker
DavyJonesLocker 2020 年 6 月 2 日
コメント済み: DavyJonesLocker 2020 年 6 月 3 日
Hi, newbie here, I am trying to create a seperate timetable variable for each data request, and then finally save all timetables in a .mat file
for i = 1:size(FTSETickers,1)
data = getMarketData(...); %returns a 'table' type
Stock = table2timetable(data);
end
save('FTSE_DATA.mat')
... however I can't seem work out how to assign the variable 'Stock' to a new name (e.g. each request corresponding to the name of the stock) each time the loop runs,
I read that works space variables should now be created dynamically , can you creat an array or timetables perhaps?
Any help , most appreciated

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 6 月 2 日
I am not exactly sure what is it you are trying to do, but I assume you want to save a file where the variable names are the ticker symbols for stock (You will get error if there are invalid characters in the symbol);
You can do something like this.
stockdata = struct();
for i = 1:size(FTSETickers,1)
%symbol = .......; % assign a char value for symbol
data = getMarketData(...); %returns a 'table' type
stockdata.(symbol) = table2timetable(data);
end
save('FTSE_DATA.mat','-struct','stockdata');
  1 件のコメント
DavyJonesLocker
DavyJonesLocker 2020 年 6 月 3 日
Thanks Mohammad, very helpful!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by