Find the values from the index in another matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a .txt file (file 1) with row numbers and 5 columns with information for an entire month, where the first column is the index. I would then like to look in other files for the values of variable G corresponding to this index. How could I do it? This is a part of file 1:
13180 -5.247 -37.274 21.2 5000
13181 -5.256 -37.274 22.5 5000
13182 -5.265 -37.274 22.0 6000
13183 -5.274 -37.274 24.5 6000
13184 -5.283 -37.274 24.2 11000
13185 -5.292 -37.274 35.0 11000
13653 -5.005 -37.265 23.0 11000
13654 -5.014 -37.265 30.0 11000
13655 -5.023 -37.265 40.5 11000
13677 -5.220 -37.265 25.5 5000
13678 -5.229 -37.265 28.8 6000
13679 -5.238 -37.265 31.7 6000
I'm trying to do it this way, but the output file is very large (about 55 GB) and with several NaN that are placed when the index is not found within that file.
str='/home/pink/Documents';
folder_name = uigetdir(str);
files = dir(fullfile(folder_name,'*.dat'));
curr_folder=pwd;
cd(folder_name);
fid = fopen('/home/pink/Documents/file_out.txt','w');
for i = 1:length(files);
fileID = fopen(files(i).name);
data = fread(fileID,[500 500], 'float32');
data((data==-99.0))=NaN;
fclose(fileID);
data = rot90(data);
latitude = [-3.63965:-0.00898:-8.12601];
longitude = [-37.5098:0.00906:-32.9831];
L1 = 1;
L2 = 500;
for LL = L1:L2;
array_lat (1:500,LL) = lat;
end
array_lati = array_lat(1:500,1:500);
array_lati;
for Lll = L1:L2;
array_long(Lll,1:500) = long;
end
array_lon = array_long(1:500,1:500);
array_lon;
file = load('/home/pink/Documents/file_input.txt');
idx = file(:,1);
lat = file(:,2);
long = file(:,3);
ref = file (:,4);
alt = file (:,5);
zdr_et = zdr(idx);
B=cat(2,idx,lat,long,ref,alt,zdr_et);
fprintf(fid,'%d %.3f %.3f %.1f %d %.1f\n',B');
end
fclose(fid);
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!