MATLAB can't create a vector -10e-6:10e-6 of a certain length. Anyone knows how to do it?

조회 수: 7 (최근 30일)
Suppose, h = 10e-6 and l = 125e-6.
I want to create two vectors of the same length, say 51. The first vector goes from -h to h, and the second vector goes from -l to l.
MATLAB computes -10e-6:10e-6 as just -10e-6, which I think is because I am dealing with very small numbers here. How can I fix this? If instead I also specify the step size -10e-6:2e-6:10e-6, then it works fine.
Thank you!
  댓글 수: 2
David Goodmanson
David Goodmanson 2018년 7월 31일
편집: David Goodmanson 2018년 7월 31일
Hi Neelima,
type 'help linspace' and take a look at that function
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 7월 31일
편집: KALYAN ACHARJYA 2018년 7월 31일
You can use linespace function to the required vector length.
vector=linespace(initial_vale,last_value,length_required)

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2018년 7월 31일
편집: Guillaume 2018년 7월 31일
This is very basic matlab here.
a:b
generates numbers from a to b in step of 1, so it generates [a, a+1, a+2, ..., a+n] with a+n <= b. So yes, -10e-6:10e-6 only generates -10e-6 since -10e-6 + 1 is greater than 10e-6.
a:k:b
generates numbers from a to b in step of k, so it generates [a, a+1*k, a+2*k, ..., a+n*k], with a+n*k <= b. So you could use for example -10e-6:10e-6:10e-6 to generate 21 numbers.
linspace(a, b, n)
generates exactly n numbers by spreading them evenly between a and b, including them. This is probably what you want here, since it sounds like you want exactly 51 numbers
linspace(-10e-6, 10e-6, 51)
  댓글 수: 1
Neelima Dahal
Neelima Dahal 2018년 7월 31일
I actually got it work. -h:h/n:h and -l:l/n:l where n is any factor does the trick. I wasn't thinking simple. Thanks anyways! :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by