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)
0 个评论
回答(2 个)
madhan ravi
2020-7-28
Use writematrix() or dlmwrite() or csvwrite() for older versions bearing in mind that
filename = 'sample'; % for example
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!