如何在Matlab中使用子字符串? [英] How do I get substring to work in matlab?
问题描述
对于这是一个新问题,我深表歉意,但是我已经在此处阅读了文档,并且在使用子字符串之前不必输入任何命令.
I apologize if this is a newb question, but I have read the documentation here and it says nothing about having to input any command before using substring.
但是,当我尝试按以下方式调用它时:
However, when I try to call it as follows:
substring('hello world',2)
substring('hello world', 2)
这给了我错误
???对于类型为'char'的输入参数,未定义的函数或方法'substring'.
??? Undefined function or method 'substring' for input arguments of type 'char'.
调用此substring
的正确方法是什么?
What is the correct way to invoke this substring
?
推荐答案
不要偏离OP的答案,实际上,OP的答案更直接地解决了您提出的问题,但是假设您要做的就是从中提取一定数量的字符一个字符串,MATLAB的索引就是您所需要的:
Not to detract from the OP's answer, which actually more directly adresses the question you ask, but assuming all you want to do is extract a certain number of characters from a string, MATLAB's indexing is all you need:
myString = 'Hello, world!';
mySubstring = myString(3:end)
mySubstring =
llo, world!
这篇关于如何在Matlab中使用子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!