Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays MATLAB:将一维字符串的单元数组转换为二维字符串_Arrays_String_Matlab_Cell Array - Fatal编程技术网

Arrays MATLAB:将一维字符串的单元数组转换为二维字符串

Arrays MATLAB:将一维字符串的单元数组转换为二维字符串,arrays,string,matlab,cell-array,Arrays,String,Matlab,Cell Array,MATLAB的最新版本有,它们是特征向量的N维矩阵。我有一个一维字符串的单元格数组,我想合并成一个二维字符串,但这样做有很多困难。和函数作用于字符串中的字符数组,但不起作用: >> cell2mat({strings(1, 4); strings(1, 4)}) Error using cell2mat (line 52) CELL2MAT does not support cell arrays containing cell arrays or objects. 有什么好办法

MATLAB的最新版本有,它们是特征向量的N维矩阵。我有一个一维字符串的单元格数组,我想合并成一个二维字符串,但这样做有很多困难。和函数作用于字符串中的字符数组,但不起作用:

>> cell2mat({strings(1, 4); strings(1, 4)})
Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects. 

有什么好办法吗?我希望上述情况下的输出是一个2x1
string
对象。

string
对象与任何其他数据类型(
double
char
等)在使用相同类型进行连接时的行为相同。只要您希望结果也是
字符串
对象,就可以使用普通连接

result = [strings(1, 4); strings(1, 4)];
或者您可以使用
cat
vertcat
更明确

result = cat(1, strings(1, 4), strings(1, 4));
result = vertcat(strings(1, 4), strings(1, 4));
或者,您可以使用索引对同一元素进行两次采样

result = strings([1 1], 4);
如果数据已在单元格数组中,则可以使用
{:}
索引生成逗号分隔的列表,并将其传递给
cat

C = {string('one'), string('two')};
result = cat(1, C{:})

作为旁注,MATLAB中没有一维数组。所有数组都至少是二维的(其中一个可以是1)。

这只是一个例子,我有单元格格式的数据,没有单独的字符串。