When creating a vector why does the size change when using a variable vs using a value?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt Thelen
am 10 Apr. 2021
Beantwortet: Stephen23
am 10 Apr. 2021
I am trying to create the time vector that starts at 0, has a step size of variable predefined (stepsize) and ends at predefined variable (fin_time).
In this case I calculated stepsize=0.0990 and fin_step=14.256
It would look like this time=[0:stepsize:fin_time]. When I type this I get a 144x1 vector.
When I type the value of stepsize manually. time=[0:0.0990:fin_time] I get a 145x1 vector. This is what I want.
How come the variable is exactly the same value but gives a different answer?
0 Kommentare
Akzeptierte Antwort
Stephen23
am 10 Apr. 2021
"How come the variable is exactly the same value but gives a different answer?"
No, the values are not exactly the same.
In one case you calculate the value, in the other case you write it explicitly. These are not the same value, but you forgot to actually check this using any reliable method (e.g. num2strexact, format hex, etc).
Read more about binary floating point numbers:
This is worth reading as well:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!