用八度音阶中的空字符串构造一个矩阵,然后在每行中填充不均匀的字符数



我在MATLAB 中有一段工作代码

empty_string = "";
bag = repmat(empty_string, 4, 1);
bag(2) = "second row";
bag(3) = "third";

然而,我想将其转换为倍频程,因为MATLAB是一个许可版本,每个人都无法访问它

empty_string = blanks(1);
bag = repmat(empty_string, 4, 1);
bag(2) = "second row";
bag(3) = "third";

这给出error: =: nonconformant arguments (op1 is 1x1, op2 is 1x10)

我希望矩阵"袋子"的每一行都填充不均匀数量的字符,请建议如何在八度音阶中完成这项工作。谢谢

由于MATLAB字符串尚未在Octave中实现,因此需要使用char数组的单元数组。幸运的是,这很简单。只需更改代码示例中的前两行即可创建适当大小的单元格数组:

bag = cell(4,1);
bag(2) = "second row";
bag(3) = "third";

结果是:

bag =
{
[1,1] = [](0x0)
[2,1] = second row
[3,1] = third
[4,1] = [](0x0)
}

一个烦恼是,为了在单元格数组中引用char数组,您需要使用大括号而不是括号:

>> second = bag{2}
second = second row

相关内容

最新更新