【问题标题】:Using sprintf in Matlab?在 Matlab 中使用 sprintf?
【发布时间】:2014-05-20 20:28:46
【问题描述】:

这类似于我之前提出的关于在 Matlab 中打开 pdf 的问题。

file = 'sl3_knt_1_2.pdf'
location = 'C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe %s'
str = sprintf(location,file);
system(str)

这会返回警告:

Warning: Invalid escape sequence appears in format string. See help sprintf for valid escape sequences. 

我认为它有一些位置变量被读取为转义序列,因为它使用 \ 但我不确定。我似乎无法让它工作。

【问题讨论】:

    标签: matlab printf


    【解决方案1】:

    试试这个:

    file = 'sl3_knt_1_2.pdf'
    location = 'C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe'
    
    str = sprintf('%s %s',location, file)
    
    system(str)
    

    【讨论】:

      【解决方案2】:

      简单的解决方案是使用“/”而不是“\”,它适用于所有平台,包括 Windows。 '\' 作为一个特殊字符是有问题的。

      【讨论】:

        【解决方案3】:

        或者,您可以像这样更改您的位置字符串:

        location = 'C:\\Program Files\\Tracker Software\\PDF Viewer\\PDFXCview.exe %s'
        

        通常\ 用于特殊字符。例如\n 是行尾。所以当你真的想写\时,你需要使用\来转义它。所以,在这种情况下你需要写\\

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-15
          相关资源
          最近更新 更多