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

3 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2018-7-5
编辑:Stephen23 2018-7-5
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by