Problem in adding column in text file
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 8 de Sept. de 2021
What error did you encounter?
We do not have that hdf file to test with.
Zhou Ci
el 8 de Sept. de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!