How can I take the derivative of data from a .csv file and store it in a table?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Justin Hollis
el 27 de Mayo de 2020
Editada: Douglas Novaes
el 11 de Sept. de 2022
I am trying to calculate acceleration from time and velocity using the code:
x=readtable('Drive Cycles EPA urban full.csv');
V=x(:,2)
T=x(:,1)
A=gradient(V(:))/gradient(T(:))
I have also tried diff instead of gradient. They both return the error:
Error using test (line 4)
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not
supported. Use a row subscript and a variable subscript.
Any suggestions would be a huge help.
Thank you!
0 comentarios
Respuesta aceptada
Cris LaPierre
el 28 de Mayo de 2020
Editada: Cris LaPierre
el 28 de Mayo de 2020
x is a table already. Therefore, V and T are also tables.
See this doc page on accessing data in a table. Basically, to do what you are trying to do, you need to use curly braces.
V=x{:,2}
T=x{:,1}
Assuming your table variables are var1 and var2, you could also do the following
V=x.var2
T=x.var1
Finally, you might find it more helpful to use meaningful variable names.
x.Properties.VariableNames = {'T','V'};
A=gradient(x.V)/gradient(x.T)
2 comentarios
Douglas Novaes
el 11 de Sept. de 2022
Editada: Douglas Novaes
el 11 de Sept. de 2022
Perfect!
Thank you.
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!