How to do simple Excel functions using Matlab instead
3 views (last 30 days)
Show older comments
Hi all,
This may be fairly easy and I apologize in advance as I am relatvely new to coding. I have have a 27 by 3 variable which contains velocity data. I want to get acceleration by dividing the change in vleocity by the chnage in time, which I have as another varibale (change in time). I know how to do this rather easily uisng Excel but I have 100's of files that I am running through Matlab so it would be much easier to add to to my Matlab code. Basicly, I want to take (2,1) from the velocity data subtract it from (1,1) and then divide it by another variable. I then want this to be repeated for all 27 in the velocity data (eg. next subtract(3,1) form (2,1) then divide by same varaible). I also want to do this for the other two rows in the same manner. What is the most efficent way to do this.
Thanks for the help!
0 Comments
Accepted Answer
Star Strider
on 7 Nov 2019
Since you actually want to take the numerical derivative (rather than calculate the differences between elements of your vectors as with the diff function), use the gradient function. (It would likely be easier to use it on each column separately, then do element-wise division.) You will likely need to experiment with it.
4 Comments
More Answers (1)
Christopher McCausland
on 7 Nov 2019
Hi Kevin,
% define array x as 3x3
% We can access each element with a process know as indexing
x = [1, 2, 3; 4, 5, 6; 7, 8, 9]
% To access the middle value we want the second row and second column, Note
% matlab starts inxexing at 1 rather than 0.
% x(rows, coloums)
x(2,2)
% Or you can access the correct element with
x(5) % 1,2,3,4,5. 5 if the fifth element in the matrix
% I'm not exactly sure what you want from the question but wrapping;
vel1(2,1)/ vel2(1,1)
% in a for loop and incrementing as required might might solve your problem?
Hope that helps,
Christopher
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!