Creating file names for save command
20 ビュー (過去 30 日間)
古いコメントを表示
I have the following code:
file_dir = 'C:\Users\mydir';
datestamp=string(datetime('now','TimeZone','local','Format','yyyyMMdd_HHmmss'));
file_name=strcat(file_dir,'sps_',datestamp,'.mat');
save(file_name);
which returns the following error:
Error using save
Argument must contain a character vector.
Not sure how to fix this?
2 件のコメント
Nagabhushan SN
2018 年 8 月 25 日
Same error:
save('temp.mat', data);
Error using save
Must be a string scalar or character vector.
回答 (2 件)
KSSV
2016 年 10 月 6 日
編集済み: KSSV
2016 年 10 月 6 日
You have to put some data in the file....
file_dir = pwd;
datestamp=string(datetime('now','TimeZone','local','Format','yyyyMMdd_HHmmss'));
file_name=strcat(file_dir,filesep,'sps_',datestamp,'.mat');
data = rand(10,10) ;
save(file_name,'data');
5 件のコメント
KSSV
2016 年 10 月 6 日
How about replacing:
file_name=strcat(file_dir,filesep,'sps_',datestamp,'.mat');
with
file_name=char(strcat(file_dir,filesep,'sps_',datestamp,'.mat'));
Thorsten
2016 年 10 月 6 日
編集済み: Thorsten
2016 年 10 月 6 日
file_dir = 'C:\Users\mydir';
datestamp=char(datetime('now','TimeZone','local','Format','yyyyMMdd_HHmmss'));
file_name=strcat(file_dir,'sps_',datestamp,'.mat');
>> whos file_name
Name Size Bytes Class Attributes
file_name 1x37 74 char
This works for me.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!