Filter löschen
Filter löschen

How can I introduce a ' \ ' after ' sprintf '

67 Ansichten (letzte 30 Tage)
Dimitris M
Dimitris M am 29 Apr. 2012
Kommentiert: Adri am 29 Jun. 2020
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

Akzeptierte Antwort

Jan
Jan am 29 Apr. 2012
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".

Weitere Antworten (2)

Image Analyst
Image Analyst am 29 Apr. 2012
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 Kommentar
Adri
Adri am 29 Jun. 2020
I logged in just to like and comment this answer. Thank you very much!

Melden Sie sich an, um zu kommentieren.


Dimitris M
Dimitris M am 29 Apr. 2012
Thank you very much
I read the documentation of course prior contacting you , but sometimes is too complex and I can not really understand it.
Thank you again for your help !
  2 Kommentare
Jan
Jan am 29 Apr. 2012
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
Daniel am 13 Nov. 2013
On the other hand, forum answers are faster than the doc for the hundreds who will come after :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Name Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by