Plotting the integral of a graph using cumtrapz.

조회 수: 15 (최근 30일)
Mher
Mher 2023년 6월 3일
이동: Matt J 2023년 6월 3일
Hi I'm very new to MATLAB. I am trying to calculate the integral of a plot from my accelerometer data over time to find the graph of velocity over time, and after using cumtrapz it seems data is getting lost or maybe I didn't set it up right. In this case I sampled 2000 points of data from accelerometer but when plotting the integral over X, it only plots the first handful of datapoints instead of all 2000 points. What am I doing wrong here? Also if someone can help me to figure out how to plot the data over actual time in second elapsed (after starting the loop or fisrt data sample), I will greatly appriciate it.
  댓글 수: 2
Torsten
Torsten 2023년 6월 3일
If you set xlim([0.4 60.4]) as you do, you shouldn't wonder that MATLAB only plots up to a1(a) = 60.4 and not till 2000.
Mher
Mher 2023년 6월 3일
I did try doing this xlim([0.0 2000.0]) ylim([-100.0 100.0]), but I'm still getting the same thing. Not only it's plotting few datapoints, values in my matrix are also being updated only up to that amount of datapoints (~60 in this case).

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

답변 (1개)

Torsten
Torsten 2023년 6월 3일
이동: Matt J 2023년 6월 3일
Then my guess is that some of the x-values (maybe starting around 60) are NaN values. Remove them before applying "cumtrapz".
  댓글 수: 1
Mher
Mher 2023년 6월 3일
이동: Matt J 2023년 6월 3일
Ahhhh, man. Thank you so much. That was the issue! I had bad samples here and there, handfull of NaN values causing the plot to break. Greatly appriciate it!

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

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by