HOW TO EXTRACT VALUES FROM MULTIPLE TEXT FILE
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tanmoyee Bhattacharya
le 2 Avr 2023
Réponse apportée : Neha
le 5 Avr 2023
I have multiple text file of latitude and longitude(data_27.75_92.45, data_27.75_92.55......). Each text file contain a single value.
I want to extract the single value of each text file in excel format. I have 15609 files. Can anybody help me?
1 commentaire
dpb
le 2 Avr 2023
Are these really text files and how/why in the world did you create 15,000 files instead of putting the values into a single file to begin with????
If they are text files, then just use the OS and copy/concatenate them all; then read the resultant file.
Attach a couple the files to be sure we know what it is you're actually dealing with if we have to, but...first let's see if we can avoid creating the problem in the first place. Explain how you got these files to start with...
Réponse acceptée
Neha
le 5 Avr 2023
It is my understanding that you have several text files where each file has its content in the following format: data_latitudeValue_longitudeValue and you want to create an excel file with data from all the text files. Please refer to the code given below, it creates an excel file with two columns: latitude and longitude along with their values.
directory = '/path/to/your/folder';
lat_lon_values = zeros(15609, 2);
file_names = dir(fullfile(directory,'*.txt'));
for i = 1:numel(file_names)
file_path = fullfile(directory,file_names(i).name);
file_content = fileread(file_path);
values=strsplit(file_content,"_");
lat_lon_values(1,i) = str2double(values{2});
lat_lon_values(2,i)=str2double(values{3});
end
T = table(lat_lon_values(1),lat_lon_values(2), 'VariableNames', {'Latitude','Longitude'});
writetable(T, 'lat_lon_values.xlsx');
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!