MATLAB: Computing second derivative from txt/csv file based on existing excel algorithm

columnsMATLABsecond derivative

Hi everyone,
I am new to Matlab. I have trouble finding anwsers to my problem. I decided to try Matlab for faster computing of my problem. I am working on my PhD from biomechanics as physiotherapist. I haave captured data from c3d files and by mokka software it can be exported for selected markers to txt file. In excel, each time I need to paste exported data to excel algoritm which I attached in a file here. Then I need to find max velocity of each move (three kicks captured for one file). It is time consuming in excel. i need to do it about 400 times. Each time it gave me only 3 results and takes around 10-15 minutes to do it. I had idea of making macro in Matlab. I want to write an alogrithm for skipping some steps. I want to import file, compute second derivative (t time, xyz -marker positions), and then find max values from 3 sectors -rows 0-700, 701-1400, 1401-2100. I cannot find commands for computing this in a same manner as it is in this excel file. Can you at least guide me how do I compute columns values row to corresponding row?

Best Answer

Here's perfect example why Matlab excels over Excel... :)
txyz=importdata('B0264_dollyo_air_P_T01 rtoe.txt',',',8); % read the text file
txyz=txyz.data; % all data in array time,x,y,z
dxyz=diff(txyz); % first differences of all columns
vxyz=dxyz(:,2:end)./dxyz(:,1)/1000; % compute velocity components
v=sqrt(sum(vxyz.^2,2)); % and the total velocity
One doesn't need to keep all the intermediary variables unless there's other need for them; kept here so can look at them and see how matches up.
The text file and the Excel file aren't the same data and the Excel file has the European "," for the decimal point so it's hard to read here in the US w/o other machinations so couldn't directly illustrate it does give identical result...
BTW, despite the Q? title, there's only a first derivative, not second...if need the second, you just "rinse and repeat" the above or use the second, optional argument to diff to compute it directly if don't need the first but this was just a step along the way...
Related Question