How do i step from a bigger number to a smaller number ?

8 次查看(过去 30 天)
I want to create an array with two numbers like this;
Xprime = x1 : 0.01 : x2
but when i make x1 > x2 i get an empty array.
Is there a solution to this ?

采纳的回答

Image Analyst
Image Analyst 2021-6-30
In general, if you don't know what x1 and x2 are, and which one will be bigger, you can do
x1 = 3
x2 = 2
inc = 0.01;
xPrime = x1 : sign(x2-x1) * inc : x2
If you know how many steps you want between the two, you can use the linspace() function instead:
numSteps = 10;
xPrime = linspace(x1, x2, numSteps)

更多回答(2 个)

Akshit Bagde
Akshit Bagde 2021-6-30
If you want to create a decrement array, you should use
Xprime = x1:-0.01:x2;

KSSV
KSSV 2021-6-30
x = 2:-0.01:1
x = 1×101
2.0000 1.9900 1.9800 1.9700 1.9600 1.9500 1.9400 1.9300 1.9200 1.9100 1.9000 1.8900 1.8800 1.8700 1.8600 1.8500 1.8400 1.8300 1.8200 1.8100 1.8000 1.7900 1.7800 1.7700 1.7600 1.7500 1.7400 1.7300 1.7200 1.7100

类别

Help CenterFile Exchange 中查找有关 Stability Analysis 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by