figure saving in created folder. Error using savepath: invalid or missing path
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Andrea Giordano
il 6 Ott 2022
Spostato: Walter Roberson
il 11 Ott 2022
While running a for loop, I create folders which name depend on the external looping variable (j). Folders creation works just fine, but if I try to save my gcf into the inner folder, I receive an error stating "Error using saveas (line 138)
Invalid or missing path: ../data_analysis/CD_plot/flow_speed_10/CD_plot_#1flow_speed10".
On the other hand, if I try to save my gcf into the current working folder "../data_analysis" or into the mid folder "../data_analysis/CD_plot", the code works fine. I do not understand what the issue is. Could it be that the just created inner folder does not yet pop up as a possible recipient directory? I highly doubt this.
Below, my for loop code.
[status, msg, msgID] = mkdir('CD_plot');
% sz = linspace(1,100,200);
for j = 1:length(sel_speed)
[status, msg, msgID] = mkdir(sprintf('../data_analysis/CD_plot/ flow_speed_%d', sel_speed(j)));
dyn_pressure = 0.5 * rho * sel_speed(j) ^ 2; % calculation of dynamic pressure
div = dyn_pressure * S;
clear k1 k2 k3 k4 k5
figure('Position', [200, 200, 800, 800])
title(['CD plot # ', num2str(j), '; Flow Speed: ', num2str(sel_speed(j))],'fontweight','bold','fontsize', 24)
hold on
grid on
xlabel('AoA [deg]','fontweight','bold','fontsize', 20);
ylabel('CD [ ]','fontweight','bold','fontsize', 20);
xlim([-10 35])
% ylim([-7 1])
for k = 1:length(MyFolderInfo)
if k == 87
continue
end
if (exp_value.vel(k) == sel_speed(j)) && (exp_value.inflation(k) == sel_inflation(1))
scatter(exp_value.aoa(k), exp_value.f_avg(k, 1) / div, 'or', 'filled', 'LineWidth',5)
if exist('k1','var') == 1
x_vec = [exp_value.aoa(k1), exp_value.aoa(k)];
y_vec = [exp_value.f_avg(k1, 1) / div, exp_value.f_avg(k, 1) / div];
plot(x_vec, y_vec, '--r')
end
k1 = k;
elseif (exp_value.vel(k) == sel_speed(j)) && (exp_value.inflation(k) == sel_inflation(2))
scatter(exp_value.aoa(k), exp_value.f_avg(k, 1) / div, 'ok', 'filled')
if exist('k2','var') == 1
x_vec = [exp_value.aoa(k2), exp_value.aoa(k)];
y_vec = [exp_value.f_avg(k2, 1) / div, exp_value.f_avg(k, 1) / div];
plot(x_vec, y_vec, '--k')
end
k2 = k;
elseif (exp_value.vel(k) == sel_speed(j)) && (exp_value.inflation(k) == sel_inflation(3))
scatter(exp_value.aoa(k), exp_value.f_avg(k, 1) / div, 'om', 'filled')
if exist('k3','var') == 1
x_vec = [exp_value.aoa(k3), exp_value.aoa(k)];
y_vec = [exp_value.f_avg(k3, 1) / div, exp_value.f_avg(k, 1) / div];
plot(x_vec, y_vec, '--m')
end
k3 = k;
elseif (exp_value.vel(k) == sel_speed(j)) && (exp_value.inflation(k) == sel_inflation(4))
scatter(exp_value.aoa(k), exp_value.f_avg(k, 1) / div, 'ob', 'filled')
if exist('k4','var') == 1
x_vec = [exp_value.aoa(k4), exp_value.aoa(k)];
y_vec = [exp_value.f_avg(k4, 1) / div, exp_value.f_avg(k, 1) / div];
plot(x_vec, y_vec, '--b')
end
k4 = k;
elseif (exp_value.vel(k) == sel_speed(j)) && (exp_value.inflation(k) == sel_inflation(5))
scatter(exp_value.aoa(k), exp_value.f_avg(k, 1) / div, 'og', 'filled')
if exist('k5','var') == 1
x_vec = [exp_value.aoa(k5), exp_value.aoa(k)];
y_vec = [exp_value.f_avg(k5, 1) / div, exp_value.f_avg(k, 1) / div];
plot(x_vec, y_vec, '--g')
end
k5 = k;
end
end
legend({'inf. = 0 mL', 'inf. = 60 mL', 'inf. = 90 mL', 'inf. = 120 mL', 'inf. = 30 mL'}, ...
'Location','north','Orientation','horizontal','fontsize', 16)
hold off
saveas(gcf, ['../data_analysis/CD_plot/flow_speed_', num2str(sel_speed(j)),'/CD_plot_#', num2str(j), 'flow_speed', num2str(sel_speed(j))], 'svg');
end
8 Commenti
Walter Roberson
il 7 Ott 2022
Please run this test code:
if ~isdir('..')
error('Corrupt or very very old file system, missing .. directory entry')
elseif ~isdir('../data_analysis')
error('No folder ../data_analysis')
elseif ~isdir('../data_analysis/CD_plot')
error('No folder ../data_analysis/CD_plot')
elseif ~isdir('../data_analysis/CD_plot/flow_speed_10')
error('No folder ../data_analysis/CD_plot/flow_speed_10')
else
fprintf('folder path ../data_analysis/CD_plot/flow_speed_10 is okay')
end
Risposta accettata
Fangjun Jiang
il 10 Ott 2022
Spostato: Walter Roberson
il 11 Ott 2022
This is really dumb.
In your code, the mkdir() line, there is an extra whitespace in front of 'flow_speed'.
So you created a folder called ' flow_speed_10' (with the leading whitespace), but you are looking for folder 'flow_speed_10'
2 Commenti
Più risposte (1)
Fangjun Jiang
il 6 Ott 2022
add "rehash" after the folder is created.
doc rehash
2 Commenti
Fangjun Jiang
il 7 Ott 2022
Do you know ".." means the parent folder of the current folder?
Add a breakpoint at the line of "saveas()", run your code and when it is paused, go to Command Window and see if you can successfully run this. If not, figure out the problem.
cd('../data_analysis/CL_over_CD_plot')
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!