HOW TO EXTRACT VALUES FROM MULTIPLE TEXT FILE
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2023-4-2
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...
采纳的回答
Neha
2023-4-5
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!