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

8 ビュー (過去 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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by