我需要在这个MATLAB字符串转义字符? [英] Do I need to escape characters in this MATLAB string?

查看:314
本文介绍了我需要在这个MATLAB字符串转义字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB调用下面的bash命令:

I would like to call the following bash command in MATLAB:

grep "Up to" ~/test_linux/vision1.1/log | awk '{print $7}'

我用系统()在MATLAB,但事实证明,有错误的:

I use system() in MATLAB, but it turns out to have errors:

>> [status string]=system('grep "Up to" ~/test_linux/vision1.1/log | awk '{print $7}' ');     
??? [status string]=system('grep "Up to" ~/test_linux/vision1.1/log | awk '{print $7}' ');  

Error: Unbalanced or unexpected parenthesis or bracket.

我需要逃避bash命令一些特殊的字符作为MATLAB字符串?

Do I need to escape some special characters in the bash command as a string in MATLAB?

推荐答案

这应该工作:

[status string]=system('grep "Up to" ~/test_linux/vision1.1/log | awk ''{print $7}'' ');

您已经逃离 另一个 如果你想让它显示为一个字符串的字符。对于在MATLAB ,处理字符串是有特殊含义(它开始和结束的字符串)中唯一字符,所以它是需要回避的唯一的一个。

You have to escape ' with another ' if you want it to appear as a character in a string. With respect to handling strings in MATLAB, ' is the only character with special meaning (it starts and ends the string), so it is the only one that needs escaping.

警告:,有些功能可能跨preT的字符串参数的方式不同,因此需要一定的字符以不同的方式进行转义。这些要求将显示每个功能的文件中。一对夫妇这些类型的函数把我的头顶部:

Caveat: Some functions may interpret their string arguments in different ways, and thus require certain characters to be escaped in different ways. These requirements will appear in the documentation for each function. A couple of these types of functions off the top of my head:


  • fprintf中 /的SPRINTF \\ 出现在格式的说法已经被转义为 %% \\\\ ,分别为。

  • REGEXP / REGEXPI :<一href=\"http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f0-42649.html#f0-42808\">Characters与常规的前pression特殊含义必须是preceded以 \\

  • FPRINTF/SPRINTF: % and \ characters appearing in the format argument have to be escaped as %% and \\, respectively.
  • REGEXP/REGEXPI: Characters with special meaning in a regular expression must be preceded with a \.

这篇关于我需要在这个MATLAB字符串转义字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆