Error using 'Save' including quotation marks around variables

7 vues (au cours des 30 derniers jours)
Nora Laine Herzog
Nora Laine Herzog le 28 Juil 2020
I am running a piece of code that generates and plots two variables (Dmed and DSEM). The code has been used by my workplace for a long time, and it works well. I did not write it.
I want the raw numbers from the plot to save into a .csv file so I can run a separate analysis later looking at the individual numbers generated.
This is a loop that runs through selected data.
Every time I try to run it, it returns the same error:
Error using save
Must be a string scalar or character vector.
save([filename, '_output', '.csv'], 'Dmed', 'DSEM')
% I have also tried this without 'Dmed' and 'DSEM', where the variables are run like this:
save([filename, '_output'], Dmed, DSEM)

Réponses (2)

madhan ravi
madhan ravi le 28 Juil 2020
Use writematrix() or dlmwrite() or csvwrite() for older versions bearing in mind that
filename = 'sample'; % for example
  1 commentaire
Nora Laine Herzog
Nora Laine Herzog le 29 Juil 2020
It is not an old version. I am using MATLAB_R2020a. Filename was defined earlier in the code, and I don't have difficulties, except when I am trying to save the variables. If I am running the full code, which plots the variables that I want to save, I get no errors. That is why I am confused.

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 29 Juil 2020
My guess is filename is a cell array containing a char row vector.
x = 1:10;
thefile = 'data571924.mat';
save(thefile, 'x') % works
thefile2 = {'data571924_cell.mat'};
save(thefile2, 'x') % fails
save(char(thefile2), 'x') % works
Many functions that can accept a char vector can also accept a cell array containing a char vector. save is not one of those many functions.

Community Treasure Hunt

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

Start Hunting!

Translated by