添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
绅士的茴香  ·  安装cplex到python_mob64ca ...·  1 月前    · 
个性的饼干  ·  实用的 Python 之 ...·  1 月前    · 
霸气的花卷  ·  python list 错位相减 ...·  2 天前    · 
憨厚的大脸猫  ·  python ...·  2 天前    · 
玩篮球的手电筒  ·  http - IIS file ...·  1 年前    · 
好帅的硬币  ·  gRPC proto ...·  1 年前    · 
独立的椰子  ·  flink sql kafka ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

There are two relevant functions. The colon : operator, you can use the linspace function. The best function to use depends on what you want to specify.

Examples:

x = -10:5:10;              % Count by 5's from -10 to 10.  (or "colon(-10, 5, 10)")
x = linspace(-10, 10, 5);  % 5 even increments between -10 and 10

The result of the colon operator will always include the first argument and the desired spacing, but generally will not include the last argument. (e.g. x = -10:5:11).

The linspace function will always include the desired first and last elements, but will the element spacing will vary. (e.g. linspace(-10, 11, 5)).

Others have mentioned the colon operator. You just have to be aware of some differences.

In Python, range takes all integer parameters and returns an integer list. In MATLAB, the colon operator can handle floating point in both the start/stop as well as the step size.

I would say that numpy.arange is a closer match to MATLAB's colon operator.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.