savefig error: Invalid argument
5 views (last 30 days)
Show older comments
Hello everyone!
This is my first post and it is rather a warning than a question. I creating a series of figures that I wanted to save (surprise!). The name for each file would be similar but variating only few parametes, thus using sprintf(...). The issue that I came across is that MATLAB was throwing me an error everytime I ran the code right in the line where savefig was telling me that the argument was invalid. I tried to save manually and it worked, so I was very confused and had to pay much more attention. After hours of bewildered search and prayers, I started 'debugging' savefig code and observed how the variables were managed. At last line of code for the savefig function I observed that the path where I wanted to save had an interesting character coming from the sprintf function: \b -- a backspace, which I intentionally was using. This is difficult to spot because the backspace is 'executed' in MATLAB's command window, but remains in the char variable, therefore invalidating the path!
If you ever have a similar error, consider the not-printable characters that might hunt your saving dreams.
Happy MATLABing!
0 Comments
Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!