[英]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.