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

查看:1023
本文介绍了我需要在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}'

我使用 system()在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}'' ');

您必须使用另一个' code>'如果您希望它在字符串中显示为一个字符。关于在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.

警告:某些功能可能以不同的方式解释其字符串参数,因此需要以不同的方式转义某些字符。这些要求将出现在每个功能的文档中。我的头顶上有几种类型的功能:

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: % 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天全站免登陆