开发者

How do I create a 1 by N matrix, with elements from 1 to N (matlab)?

quick beginner MATLAB question. How do I c开发者_Go百科reate a 1 by N matrix with elements going from 1 to N?

Ex. [1 2 3 4 ..... N]

thanks!


Just do

[1:N];

The brackets are optional.

There is also another option if you want to change the increment to something other than 1. The general pattern is

[ start : step : stop ];

So if you want only even numbers from 2 to 100, you can do

[2:2:100];

Or if you want to get numbers from 1 to 0 decrementing by .1 you can do

[1:-0.1:0];

I highly recommend you take a quick squiz through the Matlab Getting Started Guide. It covers the basics such as this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜