【发布时间】:2021-01-04 16:45:54
【问题描述】:
八度:
给定一个向量
a = 1:3
如何将向量“a”转换为字符串元胞数组
{'1','2','3'}
(这个的输出:)
ans =
{
[1,1] = 1
[1,2] = 2
[1,3] = 3
}
(问题结束)
更多信息:我的目标是使用 a 作为strcat('x',a) 的输入来获取
ans =
{
[1,1] = x1
[1,2] = x2
[1,3] = x3
}
欢迎使用其他实现此目标的解决方案,但主要问题是直接从向量中获取字符串数组。
这个问题是cell array, add suffix to every string 的后续问题,这对我没有帮助,因为strcat('x',{'1','2','3'}) 有效,但strcat('x', num2cell(1:3)) 无效:
>> strcat('x', num2cell(1:3))
warning: implicit conversion from numeric to char
warning: called from
strcat at line 121 column 8
C:/Users/USERNAME/AppData/Local/Temp/octave/octave_ENarag.m at line 1 column 1
warning: implicit conversion from numeric to char
warning: called from
strcat at line 121 column 8
C:/Users/USERNAME/AppData/Local/Temp/octave/octave_ENarag.m at line 1 column 1
warning: implicit conversion from numeric to char
warning: called from
strcat at line 121 column 8
C:/Users/USERNAME/AppData/Local/Temp/octave/octave_ENarag.m at line 1 column 1
ans =
{
[1,1] = x[special sign "square"]
[1,2] = x[special sign "square"]
[1,3] = x[special sign "square"]
}
另外,根据Matlab: How to convert cell array to string array?的Matlab函数string(a),还没有实现:
“‘字符串’函数还没有在 Octave 中实现。`
【问题讨论】:
标签: string vector type-conversion octave