Save location not working

조회 수: 1 (최근 30일)
Richard Rees
Richard Rees 2020년 2월 22일
댓글: Richard Rees 2020년 2월 23일
Morning, I have a problem with not being able to solve the problem with "Error using save: Must be a string scalar or character vector". The save directories are being created but the save function is refusing to save to these, I think it has something to do with the dates within the subfolder directories but I do not know how to save it alteratively. Could someone have a look please?
sv_direct ={'D:\One drive\OneDrive - XUniversity\PhD\TecPlot\MATLAB_sim_var\'};
coupled_data_export = num2cell(rand(3));
save_var{i} = {'coupled_data_export'};
for i = 1:length(sv_direct)
compare_locs{i} = sprintf('%s%s_subplot_figures/%s/%s/%s', sv_direct{i},string(folder_pts(5)),string(coupled_FN(1)),currDate,string(folder_pts(6)));
% Finally, create the folder if it doesn't exist already.
if ~exist(compare_locs{i}, 'dir')
mkdir(compare_locs{i});
end
end
for i = 1:length(sv_direct)
save_locs{i} = sprintf('%sEqualised_for_TP_export/%s/%s/%s', sv_direct{i},string(coupled_FN(1)),currDate,string(folder_pts(6)));
if ~exist(save_locs{i}, 'dir')
mkdir(save_locs{i});
end
end
for i = 1:length(save_var)
save_name{i} = char(save_var{i});
for k = 1 : length(save_locs)
baseFileName = char(sprintf('%s.mat', save_name{i}));
fullMatFileName = fullfile(save_locs{k}, baseFileName);
save(fullMatFileName, save_var{i});
fprintf('Saving to: %s.\n', save_locs{k});
end
end

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 22일
I guess this variable save_var{i} in the 4th last line of your code is returning a cell. Whereas, the function save expects a string scalar or a character vector.
Try casting save_var{i} to char.
sv_direct ={'D:\One drive\OneDrive - XUniversity\PhD\TecPlot\MATLAB_sim_var\'};
coupled_data_export = num2cell(rand(3));
save_var{i} = {'coupled_data_export'};
for i = 1:length(sv_direct)
compare_locs{i} = sprintf('%s%s_subplot_figures/%s/%s/%s', sv_direct{i},string(folder_pts(5)),string(coupled_FN(1)),currDate,string(folder_pts(6)));
% Finally, create the folder if it doesn't exist already.
if ~exist(compare_locs{i}, 'dir')
mkdir(compare_locs{i});
end
end
for i = 1:length(sv_direct)
save_locs{i} = sprintf('%sEqualised_for_TP_export/%s/%s/%s', sv_direct{i},string(coupled_FN(1)),currDate,string(folder_pts(6)));
if ~exist(save_locs{i}, 'dir')
mkdir(save_locs{i});
end
end
for i = 1:length(save_var)
save_name{i} = char(save_var{i});
for k = 1 : length(save_locs)
baseFileName = char(sprintf('%s.mat', save_name{i}));
fullMatFileName = fullfile(save_locs{k}, baseFileName);
save(fullMatFileName, char(save_var{i}));
fprintf('Saving to: %s.\n', save_locs{k});
end
end
  댓글 수: 1
Richard Rees
Richard Rees 2020년 2월 23일
Works. Thanks very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by