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