简体   繁体   English

从八度音阶的字符串中删除第一个字符

[英]Removing first character from a string in octave

I wanted to know how to remove first character of a string in octave. 我想知道如何在八度中删除字符串的第一个字符。 I am manipulating the string in a loop and after every loop, I want to remove the first character of the remaining string. 我正在循环中处理字符串,每个循环之后,我都想删除其余字符串的第一个字符。

Thanks in advance. 提前致谢。

If it's just a one-line string then: 如果只是单行字符串,则:

short_string = long_string(2:end)

But if you have a cell array of strings then either do it as above if you have a loop already, otherwise you can use this shorthand to do it in one line: 但是,如果您有一个单元格字符串数组,则如果已经有一个循环,则按照上面的方法进行操作,否则,可以使用此速记形式在一行中进行操作:

short_strings = cellfun(@(x)(x(2:end)), long_strings, 'uni', false)

Or else if you have a matrix of strings (ie all the same length), then you can vectorize it as: 否则,如果您具有字符串矩阵(即,所有长度相同),则可以将其向量化为:

short_strings = long_strings(:, 2:end)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM