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.

2 visualizaciones (últimos 30 días)
% 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);

Respuesta aceptada

Stephen23
Stephen23 el 28 de Nov. de 2022
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)

Más respuestas (1)

millercommamatt
millercommamatt el 28 de Nov. de 2022
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 comentarios
Jack Jones
Jack Jones el 28 de Nov. de 2022
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 el 28 de Nov. de 2022
...
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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by