Save giving a mistake "Argument must contain a character vector"

I am trying to use the save command to save the end state of two matrix and a variable of my calculation and here is part of the code that is causing the problem
if(save_state==1)
fprintf('State being saved!\n');
base_name=save_base;
base_name=strcat(base_name,'-',int2str(new_nelectrons),'-end-');
DOS_file=strcat(base_name,'DOS.mat');
OCC_file=strcat(base_name,'OCC.mat');
e_file=strcat(base_name,'e_left.txt');
fprintf('Saving OCC file to name: %s. \n',OCC_file);
save(OCC_file,'newOccupCOs');
fprintf('Done!\n');
fprintf('Saving DOS file to name: %s. \n',DOS_file);
save(DOS_file,'DOS_new');
fprintf('Done!\n');
fprintf('Saving electrons file to name: %s. \n',e_file);
fprintf(f2,'%d',new_nelectrons);
fprintf('Done!\n')
fprintf('Save successful!\n');
end
And here is the output together with error message:
Saving OCC file to name: test-1782-end-OCC.mat.
Error using save
Argument must contain a character vector.
Error in raMOmovie_forGordon>reconstruct_targets (line 2245)
save(OCC_file,'newOccupCOs');
Error in raMOmovie_forGordon>raMOmovie_run (line 976)
[OccupCOs raMOs_H1s DOS_so_far
nelectrons_left]=reconstruct_targets(filename,templatefile,orblistW,H,
DOS_so_far, OccupCOs, COs, psi_target,video_file,movie_on,
nelectrons_left,
frame_stepsize,E_COlist,DOSparameters,scalefactor,Eshift,save_state,save_base);
Error in raMOmovie_forGordon (line 738)
raMOmovie_run(filename, templatefile, videofile, nions,
orblist_bytype, electron_counts, E_Fermi,
DOSparameters,scriptcodes,scriptfiles,scalefactor,state_loaded,loaded_OccupCOs,loaded_DOS_so_far,loaded_e_left,run_save_state,save_base);
I get that this error message usually means OCC_file is not a string but I think it apparently is in this case? Could anybody help?

4 Commenti

What is class(save_base) ?
save_base is a string and as shown in the output the OCC_file have content 'test-1782-end-OCC.mat' when using fprintf with %s. So I think this means that the strcat function works properly.
Is save_base a string() object or is it a character vector? Because if it is a string object then you might just be using a release between the time that strings were introduced (R2016b) and when it became possible to pass a string to save() (which I seem to recall was R2017b, but I would need to cross-check that.)
Okay. I think that is the problem! Yes, I am using Matlab 2016 and that is really the latest version available to me. save_base is a string object. Emmmmm, is there anyway to deal with it? I tried convertStringsToChars which I found by googling but apparently my version of matlab does not support it.

Accedi per commentare.

 Risposta accettata

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by