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=22963)

poster 2019-12-10 16:49

如何在MATLAB中创建规则排列的值数组?
 
如何制作以起点,终点和总数组大小定义的数组?像数组的东西,从1到10,即20个元素长。例如,数组可能类似于:

1 1.5 2 2.5 3 3.5 ...
回答:
有两种方法可以执行此操作:
[LIST][*]使用[URL="https://www.mathworks.com/help/matlab/ref/colon.html"]冒号运算符[/URL] :

startValue = 1; endValue = 10; nElements = 20; stepSize = (endValue-startValue)/(nElements-1); A = startValue:stepSize:endValue;[*]使用[URL="https://www.mathworks.com/help/matlab/ref/linspace.html"]linspace[/URL]函数(由[URL="https://stackoverflow.com/a/1853950/52738"]Amro[/URL]建议):

startValue = 1; endValue = 10; nElements = 20; A = linspace(startValue,endValue,nElements);[/LIST]请记住,结果数组中的元素数[I]包括[/I]端点。在以上示例中,数组元素值之间的差将为9/19或略[I]小于[/I] 0.5 (与问题中的示例数组不同)。



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


所有时间均为北京时间。现在的时间是 02:08

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