HOW TO EXTRACT VALUES FROM MULTIPLE TEXT FILE

4 ビュー (過去 30 日間)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2023 年 4 月 2 日
回答済み: Neha 2023 年 4 月 5 日
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
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
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 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by