Store a number of calculations within a matrix
Mostrar comentarios más antiguos
Hi All
I am writing a small script with some functions to calculate 3 things. Velocity, acceleration and distance of a particle.
I use a while loop to increment the variable "time".
Each run through the loop, velocity, acceleration and distance are calculated using functions (i.e. I pass variables to a function and get the answer back).
This works fine. However, each loop overwrites the last. Ideally I would like to store each of the variables with time. i.e. a 2 column, n row matrix of [time, V], [time, a], [time, s]. Even better would be to have them all in one matrix ie [time, V, a, s], though I am unsure then how I would plot separate graphs for each.
Once I have that done I would then be aiming to save that matrix to a data file to open in Origin Labs. But that is another question (when I get to it!). This is my simple script:
D = 1e-6
R = D/2
Vol = (4/3)*pi*(D/2)^3
ro = 2000
mass = Vol*ro
viscosity = 1.81e-5
gravity = 9.81
time = 0
while(time<1)
V = Velocity(mass, viscosity, gravity, time, R);
a = Acceleration(mass, viscosity, gravity, time, R);
s = Distance(mass, viscosity, gravity, time, R);
time = time+1e-6;
percent = (time/1)*100
end
So before the time is stepped, I need to have stored my calculations with the time in a matrix of some sort. It is probably a simple thing to do but I am not a big user of matlab and I just can't see how it might be done.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!