How can I get my distance variable to be [0.1:0.7] to show as [0.1,0.2,0​.3,0.4,0.5​,0.6,0.7]

1 Ansicht (letzte 30 Tage)
s=[(0.1):(0.7)]
s =
0.1000
this keeps only showing only 0.1 as the resultant.
  1 Kommentar
Stephen23
Stephen23 am 12 Okt. 2022
Bearbeitet: Stephen23 am 12 Okt. 2022
How is MATLAB supposed to know that you want a step size of 0.1?
If you do not tell it otherwise, it uses the default step size of 1.
s = 0.1:0.1:0.7
s = 1×7
0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000

Melden Sie sich an, um zu kommentieren.

Antworten (2)

David Hill
David Hill am 12 Okt. 2022
s=.1:.1:.7
s = 1×7
0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000

Star Strider
Star Strider am 12 Okt. 2022
The default ‘step’ using the colon operator is 1, so the condition is immediately satisfied and only the first element appears.
An alternative —
s = linspace(0.1, 0.7, 7)
s = 1×7
0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
.

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by