How do I automatically delete a file after the variables needed has been extracted.
Mostra commenti meno recenti
ncvars={'TEC','elevation','time','x_LEO','y_LEO','z_LEO','x_GPS','y_GPS','z_GPS'};
projectdir= "F:\podtc2_data\podTc2_nrt_2022_004";
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
TEC_podtc2s=cell(num_files,1);
Elevation_podtc2s=cell(num_files,1);
times=cell(num_files,1);
x_LEOs=cell(num_files,1);
y_LEOs=cell(num_files,1);
z_LEOs=cell(num_files,1);
x_GPSs=cell(num_files,1);
y_GPSs=cell(num_files,1);
z_GPSs=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
TEC_podtc2s{i}=ncread(this_file,ncvars{1});
Elevation_podtc2s{i}=ncread(this_file,ncvars{2});
times{i}=ncread(this_file,ncvars{3});
x_LEOs{i}=ncread(this_file,ncvars{4});
y_LEOs{i}=ncread(this_file,ncvars{5});
z_LEOs{i}=ncread(this_file,ncvars{6});
x_GPSs{i}=ncread(this_file,ncvars{7});
y_GPSs{i}=ncread(this_file,ncvars{8});
z_GPSs{i}=ncread(this_file,ncvars{9});
end
So, above is my code for automatic extractation of the variables needed for my project. So the problem I am having is how would I optimise rge following code to delete the files after the variables has been extracted. From the mathworks website, it recommended a function of 'delete' is there is a better way of optimsing the loop where once it reads a singles nc file it would delete that specific file rather than using 'delete' to delete the whole folder at the end??
Many Thanks
2 Commenti
KSSV
il 2 Ago 2022
Why you want to delete the files after reading them? What those files has done to you?
Tianchu Lu
il 2 Ago 2022
Risposta accettata
Più risposte (1)
Rik
il 2 Ago 2022
0 voti
You can use delete directly on a specific file.
But the question still stands. Generally you want to process data from one form to another. I personally don't delete files automatically, unless the same code writes the analysis results somewhere. Are you sure you don't want to check whether the analysis and writing of the result is completed successfully before you delete the source files?
4 Commenti
Tianchu Lu
il 2 Ago 2022
Walter Roberson
il 2 Ago 2022
delete(this_file);
Tianchu Lu
il 2 Ago 2022
Walter Roberson
il 3 Ago 2022
ncvars={'TEC','elevation','time','x_LEO','y_LEO','z_LEO','x_GPS','y_GPS','z_GPS'};
projectdir= "F:\podtc2_data\podTc2_nrt_2022_004";
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
TEC_podtc2s=cell(num_files,1);
Elevation_podtc2s=cell(num_files,1);
times=cell(num_files,1);
x_LEOs=cell(num_files,1);
y_LEOs=cell(num_files,1);
z_LEOs=cell(num_files,1);
x_GPSs=cell(num_files,1);
y_GPSs=cell(num_files,1);
z_GPSs=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
TEC_podtc2s{i}=ncread(this_file,ncvars{1});
Elevation_podtc2s{i}=ncread(this_file,ncvars{2});
times{i}=ncread(this_file,ncvars{3});
x_LEOs{i}=ncread(this_file,ncvars{4});
y_LEOs{i}=ncread(this_file,ncvars{5});
z_LEOs{i}=ncread(this_file,ncvars{6});
x_GPSs{i}=ncread(this_file,ncvars{7});
y_GPSs{i}=ncread(this_file,ncvars{8});
z_GPSs{i}=ncread(this_file,ncvars{9});
delete(this_file); %NEW
end
Categorie
Scopri di più su Variables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!