Getting 'Argument must contain string error' error when saving, it's always worked before
    2 views (last 30 days)
  
       Show older comments
    
    Nathaniel H Werner
 on 18 Feb 2019
  
    
    
    
    
    Commented: Nathaniel H Werner
 on 18 Feb 2019
            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
0 Comments
Accepted Answer
  Geoff Hayes
      
      
 on 18 Feb 2019
        
      Edited: Geoff Hayes
      
      
 on 18 Feb 2019
  
      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')
save(fullfile(folder4Mfiles,'Position_File.mat'),'X')
More Answers (0)
See Also
Categories
				Find more on Naming Conventions in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
