Problem saving to created folders

2 visualizaciones (últimos 30 días)
Richard Rees
Richard Rees el 25 de En. de 2020
Respondida: Harsha Priya Daggubati el 28 de En. de 2020
Hello everyone,
I am having problems exporting files to created folder names. It will successfully create all the folders (inlcuding subfolders) in the various locations but only exports to the first One Drive Folder (see sv_direct). I have looked at the looping, deleted the folder locations, added a timestamp to the folders but the problem still persists. I know there is a looping probelm but I can't see it.
Could someone have a look please?
Thanks
sv_direct =[{'D:\One drive\OneDrive - X University\PhD\TecPlot\MATLAB_sim_var'},{'D:\Geostudio\TecPlot\MATLAB_sim_var'},{'D:\One drive\X University\Coastal - Shared\R R'},{'G:\Matlab_tables'}];
currDate = strrep(datestr(datetime('now')), ':', '_');
coupled_names = see attachment
%Main loop: Goes through slope angle data
for a = 1:5
% creates graphs - keeps them maximised for export
%Nested loop: Creates new folder directories - with slope angle specific subfolders (including timestamp)
for i = 1:size(sv_direct,2)
full_cycle_sav_locs{1,i} = sprintf('%s/Flu_trns_cpd_figures/%s/%s', sv_direct{i},string(coupled_names(a)),currDate);
%create the folder if it doesn't exist already.
if ~exist(full_cycle_sav_locs{i}, 'dir')
mkdir(full_cycle_sav_locs{i});
end
end
%Nested loop: Takes the subfolders above and saves figures to these locations
for k = 1 : size(full_cycle_sav_locs,2)
for j = 1:length(findobj('type','figure'))
figureBaseFile = sprintf('figure_%d.png',j);
FullfigureFile = fullfile(full_cycle_sav_locs{k},figureBaseFile);
%figure(j)
export_fig(FullfigureFile)
fprintf('Saving %s \n' ,full_cycle_sav_locs{k});
close
end
fprintf('Saving to: %s.\n', full_cycle_sav_locs{k});
end
end
end

Respuesta aceptada

Harsha Priya Daggubati
Harsha Priya Daggubati el 28 de En. de 2020
Hi,
I tried to replicate the issue, which is of no success. Can you try using breakpoint at start of loop with variable k, and check why is it not updating the other folders with figures.
This is the approach I have tried.This successfully creates png files in all the subfolders
sv_direct =[{'C:\OneDrive\One'},{'C:\OneDrive\Two'},{'C:\OneDrive\Three'},{'C:\OneDrive\Four'}];
currDate = strrep(datestr(datetime('now')), ':', '_');
%Main loop: Goes through slope angle data
for a = 1:5
% creates graphs - keeps them maximised for export
%Nested loop: Creates new folder directories - with slope angle specific subfolders (including timestamp)
for i = 1:size(sv_direct,2)
full_cycle_sav_locs{1,i} = sprintf('%s/Flu_trns_cpd_figures/%s/%s', sv_direct{i},string(coupled_names(a)),currDate);
%create the folder if it doesn't exist already.
if ~exist(full_cycle_sav_locs{i}, 'dir')
mkdir(full_cycle_sav_locs{i});
end
end
%Nested loop: Takes the subfolders above and saves figures to these locations
for k = 1 : size(full_cycle_sav_locs,2)
figure;
for j = 1:length(findobj('type','figure'))
figureBaseFile = sprintf('figure_%d.png',j);
FullfigureFile = fullfile(full_cycle_sav_locs{k},figureBaseFile);
%figure(j)
export_fig(FullfigureFile)
% savefig(FullfigureFile);
fprintf('Saving %s \n' ,full_cycle_sav_locs{k});
close
end
fprintf('Saving to: %s.\n', full_cycle_sav_locs{k});
end
end

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by