![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/712707/image.png)
how to find area under curve for every 10msec?
2 ビュー (過去 30 日間)
古いコメントを表示
Keshasni Earichappan
2021 年 8 月 11 日
編集済み: Scott MacKenzie
2021 年 8 月 15 日
Hi, i have tried finding area under curve for each parabolic curve or for every 10msec time (as shown in the figure) but i coudn't find it.I only can find the whole area under curve of the graph by using the code as i attached. How to find area under curve for every 10msec time and plot them as a graph.Hope someone can help me with this.Thank you in advance.
T1=readtable ('t.txt');
t = T1.('TIME'); v = T1.('TORQUE');
plot(t,v)
grid
xlabel('t')
ylabel('v')
title('TORQUE VS TIME')
hold on;
Area=trapz(t,v);
plot(Area)
openfig('torque vs time.fig');
0 件のコメント
採用された回答
Scott MacKenzie
2021 年 8 月 13 日
編集済み: Scott MacKenzie
2021 年 8 月 15 日
Here's solution that shows the slope (derivative) and area (integral) sample-to-sample in the signal. The sample period is 10 ms. For illustration, there are plots for the entire signal and for just the first 300 samples of the signal.
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/708907/t.txt';
M = readmatrix(f);
time = M(:,3);
torque = M(:,4);
Ps = mean(diff(time)); % sample period
% slope, sample to sample
s = diff(torque) / Ps; % slope = dy/dz
s = [0 s'];
tiledlayout(3,2);
% all samples
nexttile(1);
plot(time, torque); % signal
title('All samples');
nexttile(3);
plot(time, s); % slope (sample to sample)
title('diff (slope)');
nexttile(5);
tqa1 = (torque(1:end-1) + torque(2:end)) / 2 * Ps; % area under (sample to sample)
tqa1 = [0; tqa1];
plot(time, tqa1);
title('area under (10-ms intervals)');
% 1st 300 samples
m = 300;
nexttile(2);
plot(time(1:m),torque(1:m)); % signal
title('First 300 samples');
nexttile(4);
plot(time(1:m),s(1:m)); % slope (sample to sample)
title('diff (slope)');
nexttile(6);
tqa2 = (torque(1:m-1) + torque(2:m)) / 2 * Ps; % area under (sample to sample)
tqa2 = [0; tqa2];
plot(time(1:m),tqa2);
title('area under (10-ms intervals)');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/712707/image.png)
0 件のコメント
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!