sprintf problem working in linux but not working windows and i checked the old posts and they donot work with me?

8 visualizaciones (últimos 30 días)
i use sprintf in linux and it works perfectly but in windows it doesnot and keep giving me this error : Warning: Escaped character '\.' is not valid. See 'doc sprintf' for supported special characters. the way i am using my sprintf is like this
sprintf('C:\Users\hmo\Desktop\fast\CertTest\singleturbine%c%d.fst',a,p); a is a letter and p is a number i do not know what should i do now please help thank you so much

Respuesta aceptada

Stephen23
Stephen23 el 5 de Jul. de 2018
Editada: Stephen23 el 5 de Jul. de 2018
You need to escape all of the backslashes (this is clearly shown in the Special Character table of the sprintf documentation):
z = sprintf('C:\\Users\\hmo\\Desktop\\fast\\CertTest\\singleturbine%c%d.fst',a,p);
Simpler would be to add the path as its own separate input:
s = 'C:\Users\hmo\Desktop\fast\CertTest';
z = sprintf('%s\singleturbine%c%d.fst',s,a,p);
Best of all would be to use fullfile to join the path to the filename:
s = 'C:\Users\hmo\Desktop\fast\CertTest';
x = sprintf('singleturbine%c%d.fst',a,p);
z = fullfile(s,x);

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by