MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在MATLAB中增加列的长度 (https://www.labfans.com/bbs/showthread.php?t=23926)

poster 2019-12-10 20:48

在MATLAB中增加列的长度
 
我刚刚开始自学MATLAB,并且正在制作501x6数组。这些列将包含翻转101侧管芯的概率,因此,这些列包含101,201,301条目,而不是501。是否有一种“拉伸列”的方法,以便在有用数据的上方和下方添加0。到目前为止,我只想到制作一个像a = [zeros(200,1); die; zeros(200,1)]之类的列,以便仅数据显示在第201-301行中,并且类似地,b = [ zeros(150,1); die2; zeros(150,1)],如果我想分别在数据之前和之后添加200或150个零,以便使其适合数组。

感谢您的任何建议。



[B]回答:[/B]

您可以做几件事:

从全零矩阵开始,仅修改需要为非零的元素:

A = zeros(501,6); A(someValue:someOtherValue, 5) = value; % OR: assign the range to a vector: A(someValue:someOtherValue, 5) = 1:20; % if someValue:someOtherValue is the same length as 1:20

[url=https://stackoverflow.com/questions/3758553]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:22

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.