Documents

Matlab Short Introduction

Description
Matlab tutorial
Categories
Published
of 4
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  Labor 2 für Umweltingenieurwissenschaften ETH Zürich Page | 1 Reading and processing the meteorological data with MATLAB From the legend file you know the station metadata and the meaning and format of every field. Thus field name ‘rre150b0’ in column 10 is the precipitation in mm. Reading the data into MATLAB In the case of the ANETZ MeteoSchweiz data there are 3 lines in the header that we do not want to read, as well as the first column, so if you check the MATLAB help reference for ‘dlmread’,  you will find that the formats are: >> doc dlmread Syntax: M = dlmread(filename) M = dlmread(filename, delimiter) M = dlmread(filename, delimiter, R, C) M = dlmread(filename, delimiter, range) We could use the second to specify starting Row and Column. If you type on the MATLAB command window or in a *.m-file: >> meteodata = dlmread(['D:\umweltlabor\meteodata_data.txt'],';',3,1); This command will read from row 4 and second column onwards. You will see an array appearing on the workspace window with 1045 records and 10 fields: Alternatively    you can use the import data wizard, which probably is easier. Try ‘Import Data’ from the ‘File’ menu.   Processing the data Dealing with the data arrays (matrices) can be a bit tedious, so you may prefer to define specific variables. We know that the 7th field of ANETZ MeteoSchweiz data is temperature in degree centigrade, so we can define a temperature variable from the whole data array: >> Tair = meteodata(:,7); Now you can plot the temperature values: >> plot(Tair);  Labor 2 für Umweltingenieurwissenschaften ETH Zürich Page | 2 Convert Time Matlab has its internal timeformat (note that 1 = 1 day). Therefore it is best to convert the time vector into this format. Here is one possibility for your type of data: >> time = datenum(num2str(meteodata(:,1)),'yyyymmddHH'); You can also try to split the timenumbers i.e. 2009102003 into 2009 10 20 03 to use datenum([2009 10 20 03]). For more information about converting timeformats see ‘Date and Time Operations’ on the MATLAB HELP. Now you can make plots with better time-axes: plot(time,Tair); datetick('x','mmm');  Labor 2 für Umweltingenieurwissenschaften ETH Zürich Page | 3 Some Functions From the meteorological data provided you need to derive other data such as saturation vapour pressure (e*). We know that e* is a function of temperature and can be calculated in several ways. A simple formula is provided by the FAO e-book: () []  where ()  saturation vapour pressure at the air Temperature T [kPa], T air temperature [°C], exp[..] 2.7183 (base of natural logarithm) raised to the power [..]. This is very simple to implement in MATLAB: >> esat = 0.6108*exp((Tair.*17.27)./(Tair+237.3)); Remember the difference between A/B and A./B (See Arithmetic Operators + - * / \ ^ ' on the MATLAB HELP) We see from the definition that the results are in kPa. If we want them in hPa or milibars mb we can do: >> esat = esat.*10; >> plot(esat) Probably we have to use the saturation vapour pressure quite often, so it is worth creating a function that performs the operation whenever we call it. We do that by creating a .m file: From the file menu select New --> M-file A new window opens. Now define your function there:  Labor 2 für Umweltingenieurwissenschaften ETH Zürich Page | 4 Now save this file in the work directory of matlab as ‘esat.m’ and try:   >> plot(esat(Tair)) The plot routine call the esat function that calculates e* for all the values of Tair and plot them. NOTE: first clear the variable esat that you created before so that MATLAB does not get confused: >> clear esat >> plot(esat(Tair)) Or you ca n also call the function ‘calc_esat.m’…   This short introduction should give wings to your imagination to explore the never ending  possibilities that the software offers to your data processing....
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks