Problem in adding column in text file
Mostra commenti meno recenti
Hello everyone,
I have an hdf file containing lat, lon and another parameter hp. I also have a text file that contains lat lon values along with other variables. What I want to do is read the lat lon values from text file, match/collocate them with the lat lon of hdf and extract the hp values at corresponding points (means extract the hp at lat lon of hdf). And then place these hp values in the form of column in a text file (in the same text file).
I have tried to do this in the following way but it didn't add the column in the text file. My first question is
1) Is there a way of doing this through for loop?
2) Secondly, how to add column in the text file?
Thank you.
%% Read latitude longitude from hdf file
M_CP = hdfread('D:\MYD06_L2.A2017198.0540.061.2018034074555.hdf', 'Cloud');
M_lat = hdfread('D:\MYD06_L2.A2017198.0540.061.2018034074555.hdf', 'Latitude');
M_lon = hdfread('D:\MYD06_L2.A2017198.0540.061.2018034074555.hdf', 'Longitude');
lat_txt = tab.lat;
lon_txt = tab.lon;
lat_i = imresize(M_lat,[7570 270],'bilinear');
lon_i = imresize(M_lon,[7570 270],'bilinear');
%% To match lat lon values in text file with hdf file
mask = ismembertol(lattxt, lat_i) & ismembertol(lontxt, lon_i);
mask2 = M_CP(mask);
%% Add column in the text file
filename = 'D:\Data.txt';
Data = importdata(filename);
dlmwrite('D:\TestData', [Data mask2], '%f\n');
2 Commenti
Walter Roberson
il 8 Set 2021
What error did you encounter?
We do not have that hdf file to test with.
Zhou Ci
il 8 Set 2021
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Import and Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!