How can I introduce a ' \ ' after ' sprintf '
61 次查看(过去 30 天)
显示 更早的评论
Hello
I have a problem introducing a slash after 'sprintf' function
My code is this:
folderName1='Image_%d_TrueColor_Segmentation';
mkdir('C:\Software\AUTOMATED RESULTS\Segmented_Images',sprintf(folderName1,Num_Exe));
ab=['C:\Software\Segmented_Images\',sprintf(folderName1,Num_Exe)];
My problem occurs as I am trying to introduce a '\' after the path of 'ab' variable. I tried to intriduce it in the 'folderName1' variable at the end but did not work.
Any ideas ???
Thank you in advance
0 个评论
采纳的回答
Jan
2012-4-29
Either use \\ or insert the backslashes as string input:
sprintf('String\\backslashes\\OtherString')
sprintf('String%sOtherString', '\backlash\')
This is explained in "help sprintf". Whenever you have a problem with a specific command, reading the help and doc is recommended.
But for your problem the command fullfile would be more reliable. For details, see "help fullfile".
0 个评论
更多回答(2 个)
Image Analyst
2012-4-29
Dimitris, for simplicity, just don't use backslashes. Did you know that forward slashes work just fine for Windows paths? But anyway, the solution is to use fullfile() like Jan said - it takes care of all that for you.
1 个评论
Dimitris M
2012-4-29
2 个评论
Jan
2012-4-29
You are welcome. When reading the documentation does help, it helps faster than the forum. In addition the documentation of Matlab has a high quality. Therefore I suggest to read it whenever I can.
Daniel
2013-11-13
On the other hand, forum answers are faster than the doc for the hundreds who will come after :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!