フィルターのクリア

figure saving in created folder. Error using savepath: invalid or missing path

7 ビュー (過去 30 日間)
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
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
Andrea Giordano 2022 年 10 月 10 日
Error using data_analysis_multiple_files (line 359)
No folder ../data_analysis/CD_plot/flow_speed_10

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 10 月 10 日
移動済み: Walter Roberson 2022 年 10 月 11 日
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 件のコメント
Andrea Giordano
Andrea Giordano 2022 年 10 月 11 日
移動済み: Walter Roberson 2022 年 10 月 11 日
Dear all,
Mr. Jiang is correct. Dumb mistake, I apologize for this. I did not notice, I guess the reason is because I was too focused at finding a proper mistake.
Thank you all very much.
Andrea
Andrea Giordano
Andrea Giordano 2022 年 10 月 11 日
移動済み: Walter Roberson 2022 年 10 月 11 日
Jiang, can you write this as an answer, so I can accept it?

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 10 月 6 日
add "rehash" after the folder is created.
doc rehash
  2 件のコメント
Andrea Giordano
Andrea Giordano 2022 年 10 月 7 日
thank you, but now the error is this. (I added rehash in the loop cycle, right after creation of inner folder!
Error using saveas (line 138)
Invalid or missing path: ../data_analysis/CL_over_CD_plot/flow_speed_10/CL_over_CD_plot_#1flow_speed10
Error in data_analysis_multiple_files (line 191)
saveas(gcf, ['../data_analysis/CL_over_CD_plot/flow_speed_', num2str(sel_speed(j)),'/CL_over_CD_plot_#', num2str(j), 'flow_speed', num2str(sel_speed(j))], 'svg');
Error in run (line 91)
evalin('caller', strcat(script, ';'));
>>
Fangjun Jiang
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')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by