Warning: Escape sequence ' ' is not valid. See 'help sprintf' for valid escape sequences
4 次查看(过去 30 天)
显示 更早的评论
Im trying to create a function that changes the destination folder for some data put into a text file, trouble is that when I try to input an address such as J:\My_Documents\MATLAB into an inputdlg box, and then use sprintf on the answer so that it can be used in
filename = fullfile('Destination','Filename.txt');
sprintf thinks that the \'s in the destination name mean things like \n and \t so it gives me an error saying:
Warning: Escape sequence 'M' is not valid. See 'help sprintf' for valid escape sequences.
and sprintf itself only outputs 'J:' and not the whole destination name is there anyway I can I can change a written answer from an inputdlg box to a useful form for my purpose that doesn't try to do any unwanted formatting on it?
6 个评论
David Young
2014-9-16
Star Strider: I don't understand what sprintf is doing here. Isn't it the case that for any string s, sprintf('%s', s) is equal to s? So wouldn't
s = char(Destination);
be simpler? Have I missed something?
Guillaume
2014-9-16
Yes, sprintf('%s', s) doesn't do anything. Usually if you use the %s it's to insert a string into another.
For that matter, the char(s) is also useless, since the values returned by inputdlg are already strings, so
s = Destination;
Would work just as well and you might as well use Destination directly.
采纳的回答
Image Analyst
2014-9-16
Just avoid the situation in the first place . Use forward slashes /. Windows understands them just fine - no problem whatsoever. Perhaps that's not widely known, but yes, Windows is perfectly happy to use /, at least in MATLAB and Windows Explorer. You don't need to use backslashes at all, so don't.
2 个评论
Walter Roberson
2016-1-25
nik sharma, we will need to see your code.
Image Analyst is correct about / being accepted by MS Windows. See https://blogs.msdn.microsoft.com/larryosterman/2005/06/24/why-is-the-dos-path-character/
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!