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!