Error in csvwrite for a specific filename

1 回表示 (過去 30 日間)
Swarnava Pramanik
Swarnava Pramanik 2016 年 6 月 27 日
コメント済み: Star Strider 2016 年 6 月 27 日
Hi
I want to write a vector present in my workspace to a csv file. I'm adding a timestamp to the csv filename and for this I'm using
fileName = sprintf('sampleData%s.csv', datestr(now));
csvwrite(fileName,workspacevariable);
Wheneven I'm using the timestamp in the filename it's giving an error, without using a timestamp it works fine. Can anyone please help me in this ?
The file name contains characters that are not contained in the filesystem encoding.
Certain operations may not work as expected.
Thanks,

採用された回答

Star Strider
Star Strider 2016 年 6 月 27 日
When I run that line I get:
fileName =
sampleData27-Jun-2016 13:54:24.csv
The problem (on Windows machines) are the colons (:). Those are not legal elements of any file name. Cbange the line to:
fileName = sprintf('sampleData_%s.csv', datestr(now, 'yyyymmdd_HHMMSS'))
creating:
fileName =
sampleData_20160627_135548.csv
and it should work.
  2 件のコメント
Swarnava Pramanik
Swarnava Pramanik 2016 年 6 月 27 日
Hi Star Strider,
Thanks a lot. Yeah it was the problem, I replaced all the ":" using strrep to "-" and it worked.
Thanks,
Star Strider
Star Strider 2016 年 6 月 27 日
My pleasure.
If my Answer solved your problem, please Accept it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by