String 八度:如何将整数向量转换为字符串的单元格数组?

String 八度:如何将整数向量转换为字符串的单元格数组?,string,vector,type-conversion,octave,String,Vector,Type Conversion,Octave,八度: 给定向量 a = 1:3 如何将向量“a”转换为字符串的单元格数组 {'1','2','3'} (本报告的输出:) (问题完) 进一步信息:我的目标是使用a作为strcat('x',a)的输入,以获得 ans = { [1,1] = x1 [1,2] = x2 [1,3] = x3 } 其他实现这一目标的解决方案是受欢迎的,但主要问题是直接从向量获取字符串数组 这个问题是一个无法帮助我的后续问题,因为strcat('x',{'1','2','3')有效,但strcat

八度:

给定向量

a = 1:3
如何将向量“a”转换为字符串的单元格数组

{'1','2','3'}
(本报告的输出:)

(问题完)


进一步信息:我的目标是使用a作为strcat('x',a)的输入,以获得

ans =
{
  [1,1] = x1
  [1,2] = x2
  [1,3] = x3
}
其他实现这一目标的解决方案是受欢迎的,但主要问题是直接从向量获取字符串数组

这个问题是一个无法帮助我的后续问题,因为
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函数
string(a)
尚未实现:

“字符串”函数尚未在八度音阶中实现`


您可以组合
cellstr
int2str

strcat('x', cellstr(int2str((1:3).')))
or
cellstr(strcat('x', int2str((1:3).')))
您还可以组合
sprintf
ostsplit

ostrsplit(sprintf('x%d ', 1:3), ' ', true)
or
strcat('x', ostrsplit(sprintf('%d ', 1:3), ' ', true))

您还可以使用
num2str
代替
int2str

您可以将
cellstr
int2str
组合使用:

strcat('x', cellstr(int2str((1:3).')))
or
cellstr(strcat('x', int2str((1:3).')))
您还可以组合
sprintf
ostsplit

ostrsplit(sprintf('x%d ', 1:3), ' ', true)
or
strcat('x', ostrsplit(sprintf('%d ', 1:3), ' ', true))

您还可以使用
num2str
而不是
int2str

来添加另一个“明显的”解决方案

arrayfun( @(x) strcat('x', num2str(x)), a, 'UniformOutput', false )
或同等地

arrayfun( @(x) sprintf('x%d', x), a, 'UniformOutput', false )

只需添加另一个“显而易见”的解决方案

arrayfun( @(x) strcat('x', num2str(x)), a, 'UniformOutput', false )
或同等地

arrayfun( @(x) sprintf('x%d', x), a, 'UniformOutput', false )

前两个在x
>strcat('x',cellstr(int2str((1:3)))ans={[1,1]=x[square]}
>cellstr(strcat('x',int2str((1:3)))ans={[1,1]=x[square]}
。ostspilt解决方案有效,但我想知道使用strcat的解决方案,因此问题没有解决:如何获得
{'1','2','3'}ans={[1,1]=1[1,2]=2[1,3]=3}
来自“a”。因此问题是“如何将向量“a”转换为字符串的单元向量”。不,同样的问题,只是a
[1,1]=3]
作为签名output@questionto42它们为我工作。是否也添加了
a=1:3;cellstr(int2str(a(:))
在您的系统上工作?尝试
a=1:3;cellstr(num2str(a(:))
@questionto42
num2str
)ans={[1,1]=x[square]}和
>cellstr(strcat('x',int2str((1:3)。)ans={[1,1]=x[square]}
。ostspilt解决方案是有效的,但我想知道使用strcat的解决方案,因此问题没有解决:如何从“a}获得
>{1',2',3'}ans ans“。因此,问题是“如何将向量“a”转换为字符串的单元格向量”。不,同样的事情,只是一个
[1,1]=[square]
符号作为output@questionto42它们对我有用。
a=1:3;cellstr(int2str(a(:))
对你的系统有用吗?试试
a=1:3;cellstr(num2str(a(:))
@questionto42
num2str
也被添加了!