Error using the Save Function. "Unable to open filename.... for out"

I am having trouble saving my data using the save function.
This code works but I want to add a date time at the end of it.
%name is user inputted
save(name,'x','y')
However, I am running code multiple times so I do not want to save over the old file. I am trying to get it to save with the date time at the end of it but it doesn't seem to be working. The code is:
name1 = [name,'-',datestr(now)];
save(name1,'x','y')
However this gives me the error" Error using save Unable to open file "Name-19-Sep-2020 23:45:39" for out." When I do class(name) and class(name1) they both give me 'char' so why doesn it not save name1 and how can I save it? Thank you

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 20 日
編集済み: Ameer Hamza 2020 年 9 月 20 日

1 投票

Colon (:) are not allowed in filenames in most OS. Replace it with some other character
name1 = [name,'-',strrep(datestr(now), ':', '-')];
save(name1,'x','y')

2 件のコメント

Nicholas Carreon
Nicholas Carreon 2020 年 9 月 20 日
That worked! Thank you so much!!!!!
Ameer Hamza
Ameer Hamza 2020 年 9 月 20 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLanguage Fundamentals についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by