# How to do simple Excel functions using Matlab instead

4 ビュー (過去 30 日間)
Kevin Moore 2019 年 11 月 7 日
コメント済み: Star Strider 2019 年 11 月 7 日
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!

サインインしてコメントする。

### 採用された回答

Star Strider 2019 年 11 月 7 日
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 件のコメント表示非表示 3 件の古いコメント
Star Strider 2019 年 11 月 7 日
As always, my pleasure!

サインインしてコメントする。

### その他の回答 (1 件)

Christopher McCausland 2019 年 11 月 7 日
Hi Kevin,
You should be able to access elements on the array using a proccess known as indexing.
% 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

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!