필터 지우기
필터 지우기

Getting 'Argument must contain string error' error when saving, it's always worked before

조회 수: 3 (최근 30일)
Here is a short piece of my code.
queue = '\Q0';
Case = '\02';
path = 'D:\Data';
folder4Mfiles = strcat(path,'\Raw',queue,Case); % this corresponds to a location on my computer, I've never had trouble saving with this folder name before
cd(folder4Mfiles)
filename = sprintf('E%d.dat',ti); % Set filename as the E file of current time step
disp('E file is loading') % just what we call the files, they are just .dat format
InputData=load(filename); % Load the E file of current time step
disp('E file is done loading')
M = 352;
N = 92;
P = 352;
X = reshape(InputData(:,1),M,N,P);
save([folder4Mfiles,'\Position_File.mat'],X)
But now I get this error.
Error using save
Argument must contain a string.
I don't understand? [folder4Mfiles,'\Position_File.mat'] is a string

채택된 답변

Geoff Hayes
Geoff Hayes 2019년 2월 18일
편집: Geoff Hayes 2019년 2월 18일
Nathaniel - perhaps the error is with the second input parameter
save([folder4Mfiles,'\Position_File.mat'],X)
where you should be passing the name of the variable to save rather than the variable itself. In that case, the above would become
save([folder4Mfiles,'\Position_File.mat'],'X')
Also, consider using fullfile to build your path with filename like
save(fullfile(folder4Mfiles,'Position_File.mat'),'X')
  댓글 수: 1
Nathaniel H Werner
Nathaniel H Werner 2019년 2월 18일
It looks like both you and Jan gave the same answer, off by a minute. It's been a while since I've used this code, so I think this is a case of forgetting some of the syntax rules.
As to whether to use the variable 'path' or not, I think to be safe I will just call it Path or PATH or some other rendition of the name moving forward.
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by