Error using 'Save' including quotation marks around variables

7 次查看(过去 30 天)
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)

回答(2 个)

madhan ravi
madhan ravi 2020-7-28
Use writematrix() or dlmwrite() or csvwrite() for older versions bearing in mind that
filename = 'sample'; % for example
  1 个评论
Nora Laine Herzog
Nora Laine Herzog 2020-7-29
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.

请先登录,再进行评论。


Steven Lord
Steven Lord 2020-7-29
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.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by