フィルターのクリア

save matfile with current time stamp

15 ビュー (過去 30 日間)
Daniel Boateng
Daniel Boateng 2019 年 3 月 20 日
編集済み: Stephen23 2019 年 3 月 28 日
I want to save a matfile name optimization with the name Project and add time in addition to the name like Project_20/03/2019.mat. Please how do i do it. I tried this but it didnt work
save ('C:\dannyuser\project',optimization,datestr(now))

回答 (2 件)

StefBu
StefBu 2019 年 3 月 20 日
Hi, you have to concatenate the string first and add the fileending. Try this:
save (['C:\dannyuser\project', optimization, datestr(now), '.mat'])
Greetings
Stefan
  2 件のコメント
Daniel Boateng
Daniel Boateng 2019 年 3 月 20 日
Thanks Stefan, I tried but still getting an error
StefBu
StefBu 2019 年 3 月 28 日
What error do you get?

サインインしてコメントする。


Stephen23
Stephen23 2019 年 3 月 28 日
編集済み: Stephen23 2019 年 3 月 28 日
Do NOT concatenate paths and filenames! This is the cause of many beginners' bugs, because simple concatenation does not handle the file separator character in any way.
The simplest and recommended way is to use fullfile to join the path and filename, which automatically handles the file separator character and will avoid the errors:
D = 'C:\dannyuser\project';
F = sprintf('%s_%s.mat',optimization,datestr(now));
save(fullfile(D,F),...)

カテゴリ

Help Center および File ExchangeFile Name Construction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by