scatter data interpolation from text files in matlab
Show older comments
I am going to use scatteredInterpolant for interpolation of missing data. My data consist on text files name from Output_00 to Output_23 in a folder. Each text file consist on three columns, first is latitude, second is longitude and third is temperature. -9999.0000 value in temperature column representing NaN or missing data. This value appear randomly (some times appear in start, middle or bottom in file.
I want to make a code which read each text file from the folder and using scatteredInterpolant, interpolate 3rd column of each text file and then save this interpolated text file with output_interpol_00.text. It means there will be 24 more text files which will be interpolated
I have prepared this code. But it is manually entry requirement which is time consuming.I want to use looping or other to energize my code and instead on manully it run for all 24 text files in folder
% Load the data
data = load('Output_00.txt');
% separate the data columns, just to make the code clear
Lat = data(:,1); % Column 1 is Latitude
Lon = data(:,2); % Column 2 is Longitude
Tmp = data(:,3); % Column 3 is Temperature
% Find the "good" data points
good_temp = find(Tmp > -9999.000);
% creating vector
T = scatteredInterpolant(Lat(good_temp),Lon(good_temp),Tmp(good_temp),'linear');
% find the "bad" data points
bad_temp = find(Tmp == -9999.000);
% use the interpolation object to interpolate temperature values
interp_values = T(Lat(bad_temp),Lon(bad_temp));
% replace the bad values with the interpolated values
Tmp(bad_temp) = interp_values;
interpolant_output=[Lat';Lon';Tmp']';
fid = fopen('interpot_linear_00.txt','wt');
for ii = 1:size(interpolant_output,1)
fprintf(fid,'%.3f\t',interpolant_output(ii,:));
fprintf(fid,'\n');
end
fclose(fid)
Please also check it whether it is correct or not??
I have attached one text file of my data set. Please check it
Thanks for this kind assistance
3 Comments
Muhammad Usman Saleem
on 28 Feb 2016
Edited: Muhammad Usman Saleem
on 2 Mar 2016
Walter Roberson
on 2 Mar 2016
What assistance are you looking for at this time? The major question you seemed to have was about processing the files automatically, and the code you posted here does that.
Muhammad Usman Saleem
on 2 Mar 2016
Accepted Answer
More Answers (0)
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!