MATLAB中如何获取矩阵指定范围内的所有字符
How to get all the characters within the range specified by the matrix in MATLAB
是否可以得到矩阵指定范围内的所有字符
例如:
我的矩阵是这样的:
A = ['a' 'b' 'c'; %// Start index
'd' 'e' 'f']; %// End Index
预期输出向量(字符串元胞数组)
Out = {'abcd' 'bcde' 'cdef'}
如有任何帮助,我们将不胜感激。
希望这就是您要找的。
out = arrayfun(@colon,A(1,:),A(2,:),'uni',0);
它是如何工作的?
Elements in each row are passed one by one (at the same time) using arrayfun
and all the characters between them including the boundary characters are returned.
输入:
A = ['a' 'b' 'c';
'd' 'e' 'f'];
"Output is a vector cell-array"
输出:
>> out
out =
'abcd' 'bcde' 'cdef'
如果您希望它们采用这种格式 {'a:b','b:e','c:f'}
您可以使用此格式:
out = arrayfun(@(x,y) strcat(x,':',y),A(1,:),A(2,:),'uni',0);
>> out
out =
'a:d' 'b:e' 'c:f'
是否可以得到矩阵指定范围内的所有字符
例如:
我的矩阵是这样的:
A = ['a' 'b' 'c'; %// Start index
'd' 'e' 'f']; %// End Index
预期输出向量(字符串元胞数组)
Out = {'abcd' 'bcde' 'cdef'}
如有任何帮助,我们将不胜感激。
希望这就是您要找的。
out = arrayfun(@colon,A(1,:),A(2,:),'uni',0);
它是如何工作的?
Elements in each row are passed one by one (at the same time) using
arrayfun
and all the characters between them including the boundary characters are returned.
输入:
A = ['a' 'b' 'c';
'd' 'e' 'f'];
"Output is a vector cell-array"
输出:
>> out
out =
'abcd' 'bcde' 'cdef'
如果您希望它们采用这种格式 {'a:b','b:e','c:f'}
您可以使用此格式:
out = arrayfun(@(x,y) strcat(x,':',y),A(1,:),A(2,:),'uni',0);
>> out
out =
'a:d' 'b:e' 'c:f'