开发者

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

开发者 https://www.devze.com 2023-03-30 17:28 出处:网络
quick beginner MATLAB question. How do I c开发者_Go百科reate a 1 by N matrix with elements going from 1 to N?

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

精彩评论

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

关注公众号