-1

If I do x='bob:.mat' and then try to save it as a mat file like so:

number=10;
save(bob,'number');

I get an issue where it can't be saved, and I am assuming this is the case because: is a special character. I looked up online how to use it, and an example told me to put a ' mark before it, but that didn't work. Any help would be appreciated.

A.B.
  • 81
  • 6
  • I posted an answer too quick. What are you trying to do? – Rotem Jun 12 '19 at 21:28
  • 2
    I think the best 'solution' is *don't*, using special characters in filenames is just asking for trouble. But if you insist, tell us what o/s you are working with, as answers are likely to differ from one to the next. – High Performance Mark Jun 12 '19 at 21:32
  • You have many questions with useful answers, but have not accepted a single one. Please read here: https://stackoverflow.com/help/someone-answers . Upvoting and accepting answers is the way to thank people for their help. – Cris Luengo Jun 13 '19 at 02:11

1 Answers1

2

It should be: save('bob.mat', 'number');

Or

save bob number

save('bob', 'number'); also works.

save('bob:', 'number'); results an error (in Windows):

Error using save
Unable to open file "bob:" for output.

A file name with : is not allowed, because it's reserved for drive letters like C:.

A workaround is described here: How to get a file in Windows with a colon in the filename?

Following code actually does work:
save('bob꞉','number');

Rotem
  • 30,366
  • 4
  • 32
  • 65