I am trying to do the following. Let's imagine that you have the following arrays: mx_inelastic (30001x2434 elements), my_inelastic (30001x2434 elements), mz_inelastic (30001x2434 elements) and physical_time_inelastic (2434x1 elements). What I want to is to calculate is the first derivative with respect to time (with respect to the array physical_time_inelastic) of mx_inelastic, my_inelastic, and mz_inelastic, and then square each one and sum up them. To do this, I want to sum up all the the elements in each row of mx_inelastic, my_inelastic, and mz_inelastic, and then do the aforementioned time derivative. So at the end, on each time step I want to calculate dmdt=(d(mx_inelastic)/dt)^2+(d(my_inelastic)/dt)^2+(d(mz_inelastic)/dt)^2. For this, a for loop running over all the elements of physical_time_inelastic is neccesary. A possible problem is to calculate the temporal derivative in the first and last time step. Would there be any way to write it considering this? The first element of physical_time_inelastic is equal to zero. Moreover, I would want to create an array, squared_dmdt_inelastic (2434x1 elements) with the value of the aforementioned derivative on each step. It would be great if, at the end, I can have a .dat file of (2434x2 elements) where the first column is just physical_time_inelastic and the second column is squared_dmdt_inelastic. It would be great if all the digits generated by MatLab on the derivation process are present in the final .dat file.
Any idea on how I could face this problem?