Why does my .csv file create spaces between each of my data points? It makes it to where I cannot graph precipitation against the date.

1 次查看(过去 30 天)
% I have also attached the data I am trying to extract the data from
clearvars
clear all
clc
% Open data
fid=fopen('2022BRPREC.csv','r');
data=textscan(fid,'%s%s%s%s%s%s%s','headerlines',1,'delimiter',',');
fclose=(fid);
% Name 2022 Variables
date22=data{4};
prec22=data{5};;
figure
cc=plot(date22,prec22);

采纳的回答

Stephen23
Stephen23 2022-11-28
T = readtable('2022BRPREC.csv')
T = 365×8 table
STATION NAME DATE PRCP SNOW TAVG TMAX TMIN _______________ ____________________________________ __________ ____ ____ ____ ____ ____ {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-18 0.02 0 NaN 79 49 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-19 0 0 NaN 67 42 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-20 0 0 NaN 75 40 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-21 0 0 NaN 78 59 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-22 0.4 NaN NaN 69 44 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-23 0 0 NaN 65 37 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-24 0 0 NaN 72 39 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-25 0 0 NaN 75 54 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-26 0 0 NaN 61 42 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-27 0.01 NaN NaN 59 34 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-28 0.04 NaN NaN 65 44 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-29 0 0 NaN 67 40 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-11-30 0 0 NaN 72 37 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-12-01 0 0 NaN 76 42 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-12-02 0 0 NaN 75 49 {'USW00013970'} {'BATON ROUGE METRO AIRPORT, LA US'} 2021-12-03 0 0 NaN 75 52
plot(T.DATE,T.PRCP)

更多回答(1 个)

millercommamatt
millercommamatt 2022-11-28
You're defining the columns as strings so the output is going to include whitespace.
You want something like:
...
data = textscan(fid,'%s%s%{MM/dd/yyyy}D%f%f%f%f%f','headerlines',1,'delimiter',',');
...
  2 个评论
Jack Jones
Jack Jones 2022-11-28
Thanks for the feedback! I edited my project and it is still giving an error when trying to define the date.
% Error using textscan
% Unable to read the DATETIME data with the format "yyyy-MM-dd". If the data is not a time, use %q to get
% text data.
I changed the date format to match what is in the data. How might this be fixed?
Jack Jones
Jack Jones 2022-11-28
...
data=textscan(fid,'%s%s%{yyyy-MM-dd}D%f%f%f%f%f','headerlines',1,'delimiter',',');
...
This is what my code with the error looks like

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by