在Matlab中导入csv文件

时间:2011-11-06 02:40:02

标签: matlab csv file-io import-from-csv

我需要你的帮助才能将一些csv文件导入到matlab中。它们具有以下格式

#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

文件的第一行是空的,第二行包含#CONTENT。我想在矩阵中包含Pressure,O3PartialPressure,Temperature,WindSpeed,WindDirection,LevelCode,Duration,GPHeight,RelativeHumidity,SampleTemperature

行下的所有数据

1 个答案:

答案 0 :(得分:1)

使用csvread()功能。来自documentation

  

csvread读取逗号分隔值文件。       M = csvread('FILENAME')读取逗号分隔值格式的文件       文件名。结果以M形式返回。文件只能包含       数值。

在您的情况下,由于您要排除#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'.