简体   繁体   English

在Matlab中导入CSV文件

[英]Import csv file in Matlab

I need your help to import some csv files into matlab. 我需要您的帮助才能将某些csv文件导入到matlab中。 They have the following format 它们具有以下格式

#CONTENT
Class,Category,Level,Form
xxxxx,xxxxx,1.0,1

#DATA_GENERATION
Date,Agency,Version,ScientificAuthority
2010-04-08,INME,1.0,XXX xxx xxxx

#PLATFORM
Type,ID,Name,Country,GAW_ID
STN,308,xxxx,xxx

#INSTRUMENT
Name,Model,Number
ECC,6A,6A23500

#LOCATION
Latitude,Longitude,Height
25,-3,631.0

#TIMESTAMP
UTCOffset,Date,Time
+00:00:00,2010-04-07,10:51:00
* SOFTWARE: SNDPRO 1.321
* TROPOPAUSE IN MB 184
* 

#FLIGHT_SUMMARY
IntegratedO3,CorrectionCode,SondeTotalO3,CorrectionFactor,TotalO3,WLCode,ObsType,Instrument,Number
328.4,0,379.9

#AUXILIARY_DATA
MeteoSonde,ib1,ib2,PumpRate,BackgroundCorr,SampleTemperatureType,MinutesGroundO3
RS92-SGPW,,,,Pressure,Pump

#PUMP_CORRECTION
Pressure,Correction
2.0,1.171
3.0,1.131
5.0,1.092
10.0,1.055
20.0,1.032
30.0,1.022
50.0,1.015
100.0,1.011
200.0,1.008
300.0,1.006
500.0,1.004
1000.0,1.000

#PROFILE
Pressure,O3PartialPressure,Temperature,WindSpeed,WindDirection,LevelCode,Duration,GPHeight,RelativeHumidity,SampleTemperature
945.36,4.590,14.6,10.0,30,2,0,631,43,22.8
944.90,4.620,14.3,7.8,20,0,2,635,44,22.8
943.51,4.630,13.9,7.6,17,0,4,647,44,22.8
942.13,4.620,13.4,8.1,16,0,6,660,45,22.8
940.98,4.590,13.0,9.0,16,0,8,670,45,22.8
939.83,4.590,12.6,9.8,17,0,10,680,46,22.8
938.69,4.600,12.1,10.3,18,2,12,691,46,22.8
937.77,4.600,12.2,10.9,18,0,14,699,47,22.9
936.63,4.600,12.1,11.4,19,0,16,709,47,22.9
935.48,4.600,11.8,11.9,19,0,18,719,47,22.9
934.12,4.600,11.7,12.3,19,0,20,731,47,22.9
932.98,4.590,11.6,12.6,19,0,22,742,48,22.9
931.84,4.590,11.6,12.9,18,0,24,752,48,22.9
930.93,4.600,11.6,13.2,18,0,26,760,48,22.9
929.79,4.600,11.4,13.4,17,0,28,770,49,22.9
928.88,4.610,11.5,13.6,16,0,30,778,49,22.9
927.98,4.620,11.4,13.7,15,0,32,787,49,23.0
927.30,4.620,11.3,13.8,14,0,34,793,49,23.0

The first line of the file is empty and second line contains the #CONTENT . 文件的第一行为空,第二行包含#CONTENT I would like to have in a matrix all data that are under the line Pressure,O3PartialPressure,Temperature,WindSpeed,WindDirection,LevelCode,Duration,GPHeight,RelativeHumidity,SampleTemperature 我想在矩阵中具有Pressure,O3PartialPressure,Temperature,WindSpeed,WindDirection,LevelCode,Duration,GPHeight,RelativeHumidity,SampleTemperature行下的所有数据

Use the csvread() function. 使用csvread()函数。 From the documentation : 文档中

csvread Read a comma separated value file. csvread读取逗号分隔的值文件。 M = csvread('FILENAME') reads a comma separated value formatted file FILENAME. M = csvread('FILENAME')读取以逗号分隔的值格式的文件FILENAME。 The result is returned in M. The file can only contain numeric values. 结果以M返回。文件只能包含数字值。

In your case, since you want to exclude all of the content up until the #PROFILE data, you would have to know the line number of the data you're interested in in advance, then use one of the following uses (again from the documentation): 在您的情况下,由于要在#PROFILE数据之前排除所有内容,因此您必须事先知道您感兴趣的数据的行号,然后使用以下用途之一(同样从文档):

 M = csvread('FILENAME',R,C) reads data from the comma separated value formatted file starting at row R and column C. R and C are zero- based so that R=0 and C=0 specifies the first value in the file. M = csvread('FILENAME',R,C,RNG) reads only the range specified by RNG = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of the data to be read and (R2,C2) is the lower-right corner. RNG can also be specified using spreadsheet notation as in RNG = 'A1..B7'. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM