尝试绘制CSV文件

时间:2016-03-03 19:07:34

标签: matlab csv plot

我试图绘制一个CSV文件,这就是它的样子:

Date    Ebola: Case counts and deaths from the World Health Organization and WHO situation reports
3/22/2014   49
3/24/2014   86
3/25/2014   86
3/26/2014   86
3/27/2014   103
3/28/2014   112
3/29/2014   112
3/31/2014   122
4/1/2014    127
4/4/2014    143
4/7/2014    151
4/9/2014    158
4/11/2014   159
4/14/2014   168
4/16/2014   197
4/17/2014   203
4/20/2014   208
4/23/2014   218
4/26/2014   224
5/1/2014    226
5/3/2014    231
5/5/2014    235
5/7/2014    236
5/10/2014   233
5/12/2014   248
5/23/2014   258
5/27/2014   281
5/28/2014   291
6/1/2014    328
6/3/2014    344
6/10/2014   351
6/16/2014   398
6/18/2014   390
6/20/2014   390
6/30/2014   413
7/2/2014    412
7/6/2014    408
7/8/2014    409
7/12/2014   406
7/14/2014   411
7/17/2014   410
7/20/2014   415
7/23/2014   427
7/27/2014   460
7/30/2014   472

我将它导入我的MATLAB工作区。现在我想用MATLAB绘制这些数据,但是我该怎么做呢?我对每列的变量是DateEbolaCaseCountsAndDeathsFromTheWorldHealthOrganizationAndWHOsit(抱歉,我不知道如何缩短后一个变量)。

我尝试过plot(Date, EbolaCa[...]),但它给了我一个错误。什么是正确的方法?

1 个答案:

答案 0 :(得分:1)

您必须同时使用datenum()datetick()来实际显示x轴上的日期。我能够按如下方式创建您的表格片段:

T={'3/22/2014'   49
'3/24/2014'   86
'3/25/2014'   86
'3/26/2014'   86
'3/27/2014'   103
'3/28/2014'   112
'3/29/2014'   112
'3/31/2014'   122
'4/1/2014'    127
'4/4/2014'    143
'4/7/2014'    151
'4/9/2014'    158
'4/11/2014'   159
'4/14/2014'   168
'4/16/2014'   197
'4/17/2014'   203
'4/20/2014'   208
'4/23/2014'   218
'4/26/2014'   224
'5/1/2014'    226
'5/3/2014'    231
'5/5/2014'    235
'5/7/2014'    236
'5/10/2014'   233
'5/12/2014'   248
'5/23/2014'   258
'5/27/2014'   281
'5/28/2014'   291
'6/1/2014'    328
'6/3/2014'    344
'6/10/2014'   351
'6/16/2014'   398
'6/18/2014'   390
'6/20/2014'   390
'6/30/2014'   413
'7/2/2014'    412
'7/6/2014'    408
'7/8/2014'    409
'7/12/2014'   406
'7/14/2014'   411
'7/17/2014'   410
'7/20/2014'   415
'7/23/2014'   427
'7/27/2014'   460
'7/30/2014'   472};
T=cell2table(T);
T.Properties.VariableNames={'Date','Ebola'};

其中第一列由字符串组成,第二列由数字组成。要生成plot(),您可能需要执行类似

的操作
figure(1);
plot(datenum(T.Date,'m/dd/yyyy'),T.Ebola);
datetick('x','dd/mmm/yyyy'); grid on;

显示

enter image description here

但是,您可以随意调整datenum()datetick()格式。