Read a csv file???

Dear all, in the first row of the matrix are 6 variable names (time, open, high, low, close, volume). The format of the data in the first column (time) is like this: 01.01.2004 01:00:00.000. The time is so complicated, because it is a high frequency data set of an exchange rate. In all other columns are exchange rates. Every entry is separated by a comma. When I use the Import Wizard of Matlab, it separates the data into two sets. In the first set (text file) are only the variable names and the whole column time and in the second data set are all exchange rates. How can I read in the csv-file correctly and as a whole? Thank you in advance!

6 件のコメント

José-Luis
José-Luis 2013 年 1 月 8 日
What does correctly mean to you? From what I hear, you can read the data, it is not just in the format you want.
Thor
Thor 2013 年 1 月 8 日
Yes, that's right. The Wizard separates it into two sets. On the one hand side I have the exchange rates and on the other hand I have the variables and the time. But I want it as one matrix!
José-Luis
José-Luis 2013 年 1 月 8 日
You could try importdata() instead.
Thor
Thor 2013 年 1 月 8 日
編集済み: Thor 2013 年 1 月 8 日
When I use importdata(), I have again two parts:
data (105384x5) double and textdata (105385x6 cell)
So is there another possibility?
José-Luis
José-Luis 2013 年 1 月 8 日
How do you expect to convert the time to a number? I don't really understand how you want your data to look like. If you want a single matrix, then you can concatenate whatever it is that you obtain and save everything to a cell array.
per isakson
per isakson 2013 年 1 月 8 日
I have answered similar questions a number of time here at Answer. I would use textscan.

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

 採用された回答

Matt J
Matt J 2013 年 1 月 8 日
編集済み: Matt J 2013 年 1 月 8 日

0 投票

If you want date info and numeric info to co-exist in a matrix (not a cell array), you must first convert the date info into a numeric form, e.g., using the DATENUM command. Then concatenate them together as José-Luis recommends.
The example date you provided, for instance, could be converted as follows
>> datenum('01.01.2004 01:00:00.000','mm.dd.yyyy HH:MM:SS')
ans =
7.3195e+05

2 件のコメント

Thor
Thor 2013 年 1 月 9 日
Now I have a matrix. But the date is still a number! How can I re-transform the datecolumn?
Matt J
Matt J 2013 年 1 月 9 日
編集済み: Matt J 2013 年 1 月 9 日
Using DATESTR.

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2013 年 1 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by