フィルターのクリア

Read string data (date & time) from CSV file

64 ビュー (過去 30 日間)
amit dhoke
amit dhoke 2015 年 8 月 6 日
コメント済み: Mohammad Ali Miri 2021 年 12 月 18 日
I have a following data into the'NovDay.csv' file
datetime airtemp insolation windspeed winddirection power (W) energy (Wh)
5/01/2015 5:00 20.3 3.3 1.5 208 0 0
5/01/2015 5:01 20.3 5 2.6 191 0 0
5/01/2015 5:02 20.3 6.5 1.8 166 0 0
5/01/2015 5:03 20.3 7.9 2 225 0 0
5/01/2015 5:04 20.3 7.9 1.1 198 0 0
5/01/2015 5:05 20.3 11.1 2 211 0 0
5/01/2015 5:06 20.3 15.6 1.8 199 0 0
5/01/2015 5:07 20.3 17.7 1.8 189 84 1
I am using the below command to read the csv file
Nov=csvread('NovDay.csv',2,1);
but I am getting only the below data
20.3000000000000 5 2.60000000000000 191 0 0
20.3000000000000 6.50000000000000 1.80000000000000 166 0 0
20.3000000000000 7.90000000000000 2 225 0 0
20.3000000000000 7.90000000000000 1.10000000000000 198 0 0
20.3000000000000 11.1000000000000 2 211 0 0
20.3000000000000 15.6000000000000 1.80000000000000 199 0 0
20.3000000000000 17.7000000000000 1.80000000000000 189 84 1
here the date and time is missing.
I want to read the date and time data.
  1 件のコメント
Mohammad Ali Miri
Mohammad Ali Miri 2021 年 12 月 18 日
use readtable()

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

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 8 月 6 日
編集済み: Walter Roberson 2015 年 8 月 7 日
Use
[a,b,c]=xlsread('NovDay.csv')
  2 件のコメント
amit dhoke
amit dhoke 2015 年 8 月 6 日
Thanks Azzi I tried to use this command, it separating string and number in a,b,c. But I have to plot the time from this array with my results. If you could explain me, how to separate date and time from first coulumn and then read that time into an array. Then it can be easy to plot that time against any results.
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 8 月 7 日
Suppose the first column looks like:
c1={'01/01/2015 00:00:00';'02/01/2015 00:20:10';'03/01/2015 12:00:02'}
s=datenum(c1,'dd/mm/yyyy HH:MM:SS')
date=datestr(s,'dd/mm/yyyy'),
time=datestr(s,'HH:MM:SS')

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


Walter Roberson
Walter Roberson 2015 年 8 月 6 日
Use xlsread(). Or textscan(). csvread() can only read numeric fields.

Mehran Mustafa
Mehran Mustafa 2017 年 2 月 28 日
Hello
I have date, time and wind speed data in three columns. The data is 1 min average. I want to convert it to hourly average by using a loop. How do I read the date and time and then use is in for loop?
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 28 日
If you have a new enough MATLAB, you can read the data using readtable() and convert the resulting table() object to a timetable() object which then has direct functions to group by time.
Otherwise, the easiest way to read the date and time depends on which MATLAB release you have?
Peter Perkins
Peter Perkins 2017 年 2 月 28 日
As Walter says, if possible, use readtable. Even prior to R2016b, back to R2013b, it's usually the best choice.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by