How to do simple Excel functions using Matlab instead

조회 수: 2 (최근 30일)
Kevin Moore
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
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
Kevin Moore
Kevin Moore 2019년 11월 7일
Thank you again, I was able to use the information you provided to get it to work perfectly!!
Star Strider
Star Strider 2019년 11월 7일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Christopher McCausland
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by