필터 지우기
필터 지우기

use workspace variables as input to generate multiple text file outputs

조회 수: 2 (최근 30일)
Charles
Charles 2019년 5월 4일
댓글: Charles 2019년 5월 6일
I have n workspace variables which all happen to be tables. The following script takes one such variable for example GPB_USD as input. It does a numnber of operations
but eventually generates a text file output with name GBPUSD1d.
The rexr file contain three columns, A colum of dates, and two columns of prices.
I wish to generate text files for each of the tables in the workspace and name them appropriately as .txt files. \
For example USD_CHF, should produce a textfile USDCHF1d etc
cd '/Users/cg/Documents/MATLAB/code 7/Selection'
tst=USD_NOK.Date(1:height(USD_NOK(2:end,2))); % just a sample set to play with
mydates = datetime(tst,'InputFormat','yyyy-MM-dd''T''HH:mm:ss.SSSSSSSSSZ ', ...
'TimeZone','Europe/London','Format','yyyyMMddHHmmss')
% size(AUDCAD)
USD_NOK1d = horzcat(num2cell(mydates), USD_NOK(2:end,5));
USD_NOK1d.New=USD_NOK1d.Close; % make a new column with content of close
cd '/Users/cg/Forex-and-Stock-Python-Pattern-Recognizer-master/data'
writetable(USD_NOK1d,'USD_NOK1d','WriteVariableNames',0) % write a text file without header ...

채택된 답변

Jan
Jan 2019년 5월 6일
Data = load('INPUTFILE.mat');
DataName = fieldnames(Data);
for k = 1:numel(DataName)
ThisName = DataName{k};
ThisData = Data.(ThisName);
...your code using the current values
OutputName = [strrep(ThisName, '_', ''), '1d'];
...
end
  댓글 수: 2
Charles
Charles 2019년 5월 6일
Thank you for this. I am reading through each line. What I understand is
load input data, which will be some 76 table arrays
assign field names to the variable data
then loop: for through each field name, and assing it to variable name ThisName, then also assign data from each table to ThisData
my code using the value for GhiusName and ThisData will produce each text file
Output will name the resultant text file.
I am thinking there is more than one feild name per file, however lets run the code and see.
Thanks
Charles
Charles 2019년 5월 6일
Perfect. I change the order of one line in the cod eit it works. Thank you so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by