Problem in adding column in text file
显示 更早的评论
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 个评论
Walter Roberson
2021-9-8
What error did you encounter?
We do not have that hdf file to test with.
Zhou Ci
2021-9-8
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!