MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何用特定值初始化矩阵的所有条目? (https://www.labfans.com/bbs/showthread.php?t=26295)

poster 2019-12-14 20:13

如何用特定值初始化矩阵的所有条目?
 
在[URL="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29"]Haskell中[/URL] ,如果我想获取仅包含数字5的10元素列表,则可以执行以下操作:

take 10 $ repeat 5 输出:

[5,5,5,5,5,5,5,5,5,5] Matlab中有类似的东西吗?



[B]回答:[/B]

将重复的值分配给数组很容易:

x(1:10) = 5; 如果要在语句中内联生成元素数组,请尝试以下操作:

ones(1,10) * 5 或搭配[URL="http://ch.mathworks.com/help/matlab/ref/repmat.html;jsessionid=f1464648af2c6b017506485689f6"]repmat[/URL]

repmat(5, 1, 10)

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


所有时间均为北京时间。现在的时间是 04:49

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