clc;clear;

% Create an empty array to store the electron density data

ne_array = [];

% Loop through the files in the folder

folder_path = 'D:\ionPrf_prov1_2020_002'; % replace with the path to your folder

file_list = dir(fullfile(folder_path, '*.0001_nc')); % replace '.0001_nc' with the file extension of your data files

for i = 1:numel(file_list)

% Read the electron density data from the file

filepath = fullfile(folder_path, file_list(i).name);

fid = fopen(filepath, 'r');

while ~feof(fid)

line = fgetl(fid);

if startsWith(line, 'ELEC_dens') % look for the line starting with 'Ne'

ne_data = strsplit(line);

ne_data = str2double(ne_data(2:end)); % extract the Ne data as an array of doubles

ne_array = [ne_array; ne_data]; % add the Ne data to the array

end

end

fclose(fid);

end

% Save the electron density data to a text file

output_filename = 'ne_data.txt';

dlmwrite(output_filename, ne_array, 'delimiter', '\t', 'precision', '%.3e');

More Ahmed Abdelaziz's questions See All
Similar questions and discussions