2011-11-06 118 views
0

我需要你的幫助來將一些csv文件導入到matlab中。它們具有以下格式在Matlab中導入csv文件

#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

使用csvread()函數。來自documentation

csvread讀取逗號分隔值文件。 M = csvread('FILENAME')讀取逗號分隔值格式文件 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'. 
+0

非常感謝您的幫助 –