Error using 'Save' including quotation marks around variables
7 views (last 30 days)
Show older comments
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)
0 Comments
Answers (2)
madhan ravi
on 28 Jul 2020
Use writematrix() or dlmwrite() or csvwrite() for older versions bearing in mind that
filename = 'sample'; % for example
Steven Lord
on 29 Jul 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.
0 Comments
See Also
Categories
Find more on Whos 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!