在八度构建一个带有空字符串的矩阵,然后在每行中用不均匀的字符填充

发布于 2025-01-19 15:24:22 字数 451 浏览 2 评论 0原文

我在 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 argument (op1 is 1x1, op2 is 1x10)

我希望矩阵“bag”的每一行都填充奇数个字符,请建议如何做到这一点八度。谢谢。

I have a working piece of code in MATLAB

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

However, I want to convert this to octave as MATLAB is a licensed version and everyone can't get access to it.

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

This gives error: =: nonconformant arguments (op1 is 1x1, op2 is 1x10)

I want each row of matrix 'bag' to be filled with uneven number of characters, please suggest how this can be done in octave. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆兒滾 2025-01-26 15:24:22

由于matlab strings> strings 尚未在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

Since MATLAB strings have not been implemented in Octave, you will need to use a cell array of char arrays. Fortunately, this is pretty simple. Just change the first two lines in your code sample to create a cell array of the proper size:

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

The result is:

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

The one annoyance is that in order to reference your char arrays in the cell array, you need to use curly braces instead of parentheses:

>> second = bag{2}
second = second row
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文