figure saving in created folder. Error using savepath: invalid or missing path
古いコメントを表示
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 件のコメント
Walter Roberson
2022 年 10 月 7 日
What is the total length of filename with all directories included?
Andrea Giordano
2022 年 10 月 7 日
Walter Roberson
2022 年 10 月 7 日
That is a relative file name. If you expand the name out completely with the C:\ all the way to the end, then what is length() of the resulting name?
Andrea Giordano
2022 年 10 月 7 日
Walter Roberson
2022 年 10 月 7 日
could I ask you to experiment by changing the # character to _ (underscore)?
Andrea Giordano
2022 年 10 月 7 日
Walter Roberson
2022 年 10 月 7 日
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
Andrea Giordano
2022 年 10 月 10 日
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2022 年 10 月 6 日
0 投票
add "rehash" after the folder is created.
doc rehash
2 件のコメント
Andrea Giordano
2022 年 10 月 7 日
Fangjun Jiang
2022 年 10 月 7 日
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')
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!