Download sonde data to your directory
I downloaded a Vandenberg sounding (12Z Sep 29) from NOAA. Go ahead and download this file to your working directory by right clicking on the link below and saving the file.
Vandenberg Sounding File
Open the file in an editor of your choice. Looking at information on the format of the sonde file reveals that the first 4 rows are header data. We need to delete these lines before loading the ASCII data into Matlab.
Loading ASCII data
Now that you've cropped the header information, we can load the ASCII data into Matlab.
load VBG.txt % loads matrix with size 110x7 p = VBG(:,2); % save pressure to variable 'p' T = VBG(:,4); plot(T/10,p/10); % plot pressure (in mb) versus temperature (degrees C) axis('ij') % this flips the y-axis so that pressure decreases upward
Skipping bad data
Well, that plot doesn't look very good. It's because the bad data points are filled with the value '99999'. We want to replace those values with 'NaN' (not a number). When plotting, Matlab skips values that are NaN.
pcorr = p; % save pressure to the 'corrected pressure' variable pcorr(find(p==99999)) = nan; % find all values that equal 99999 and replace with NaN % notice that '==' is use for logical comparison Tcorr = T; Tcorr(find(T==99999)) = nan; plot(Tcorr/10,pcorr/10); axis('ij')But what if we don't want breaks in our plot?
nums = find( (~isnan(Tcorr)) & (~isnan(pcorr)) ); % this saves the indices of points that % are NOT NaN (i.e. are actual numbers) in BOTH Tcorr and pcorr plot(Tcorr(nums)/10,pcorr(nums)/10); axis('ij');
Saving/Loading Matlab formatted data
% omitting the variable list will save all current variables to % the .mat file clear load vgb.mat
Direct File I/O
Here is a list of commands that useful for reading formatted data directly from files.
fgetl % read one line from a file and save to buffer sscanf % scan the buffer for specific data fprintf % write data to the screen or to a fileFormatting data follows C conventions. See the help pages under 'fprintf' for more information.
Try it yourself
Load one of the other variables from the sounding (dewpoint, wind direction, wind speed) and plot it versus height.