Read and taking selected lat-longs from few .loc files and plot in geoshow

I have 92 .loc files in the current folder. The volume of all the files is large. I need to read all the files one by one and select column 2 and 3 (lats and lons) in 30N to 90N latitudinal range. And place them in one .mat file. Therefore with that .mat file I can plot a geoshow map. How to do that?

5 Comments

hello
your files can probably be read by the many available functions to read txt /ascii files
what have you tried so far ? success ?
if you still need help please provide your code + at least one file (or extract of it) (use the paper clip)
Is it possible to attach 2 .loc files?
Even if I zipped, the size of the files exceeds 5 mb uploading limit of Matlab
For each fie, you can cut it down to few lines.
clear all
myFolder = 'U:\W\';
filePattern = fullfile(myFolder, '*.loc');
Files = dir(filePattern);
for k =1:length(Files)
% k=1
baseFileName = Files(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
fid = fopen(fullFileName,'rt');
a = textscan(fid, '%s %s %f %f %f %f %f', ...
'Delimiter',',', 'CollectOutput',1);
M(:) = [a{2}];
M1=M(:,1:2);
lat_idx=find(M1(:,1)>=30 & M1(:,1)<=90);
WSC=M1(lat_idx,:);
end
I have done that much. I think it reads all the files, but giving the output for one file only. It should be somethink like : It will read first file, keep the first and second column and put the other file's first and second column in the same .mat file.

Sign in to comment.

Answers (0)

Asked:

on 30 Aug 2022

Commented:

on 6 Sep 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!