[英]construct a matrix with empty string in octave and later fill it with uneven number of characters in each row
我在 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 中实现,您将需要使用字符 arrays 的元胞数组。幸运的是,这非常简单。 只需更改代码示例中的前两行即可创建大小合适的元胞数组:
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 arrays,您需要使用大括号而不是圆括号:
>> second = bag{2}
second = second row
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.