フィルターのクリア

How can I Insert a CSV filename into my array

2 ビュー (過去 30 日間)
AR
AR 2016 年 11 月 2 日
回答済み: Walter Roberson 2016 年 11 月 2 日
Need help with preparing data.
I'm creating an array by appending 500 csv files of daily stock data (varying rows), each with 7-columns using with code below.
How can I create an 8th column with the filename (or just part of the filename) so I can later identify which file belongs with which rows of data?
Thanks.
dname='C:\project\';
alldata=[];
files=dir([dname,'*.csv']);
for i=1:length(files);
csvdata=csvread([dname,files(i).name]);
alldata=[alldata;csvdata];
end

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 2 日
You cannot. csvread() only reads numeric data, so your arrays would be numeric. You cannot store character strings in numeric arrays.
  • You can create separate variables.
  • You can switch to a cell array -- num2cell() the numeric data and then horzcat() on the cell array of strings
  • You can use array2table() to convert to a table() data structure and then add the file names as a column of that.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by