matlab calculation area circular

7 次查看(过去 30 天)
I have a signal and want to calculate the area. The problem is that i want to make a loop with decimal step, because the length is 1189,58
Any ideas how to proceed with the loop?
  2 个评论
Rik
Rik 2020-9-25
Comment posted as answer (and erroneously flagged by the spam filter) by Sirius8:
Noone? Come on guys a little help!
Rik
Rik 2025-1-8
Why did you delete all your comments? Now most of my comments have a greatly reduced value for future readers. You were told the same thing 2 years ago here.

请先登录,再进行评论。

采纳的回答

Rik
Rik 2020-9-25
编辑:Rik 2020-9-28
You can use trapz for a numerical approximation of an integration. By selecting your bounds you can use this to calculate the area under a curve.
Edit:
Using the code you posted and adding the loop I'm getting something similar to what you describe. If you don't want the legend entries, you should use explicit handles in your call to legend.
S=load('test1.mat');
[x1,y1,y11]=deal(S.x1,S.y1,S.y11);
figure(1),clf(1)
subplot(2,1,1)
plot(x1,y1)
grid on
hold all
plot(x1,y11,'m')
grid on
hold all
legend ('normalized fft','smoothed')
subplot(2,1,2)
plot(x1,y11,'m')
grid on
hold all
legend ('smoothed')
cmap=colormap('prism');n_col=0;
freq_range=5;
for x_start=0:freq_range:max(x1)
x_end=x_start+freq_range;
L=x1>=x_start & x1<=x_end;
if sum(L)<=1,continue,end%skip if there is only 1 point
X=[x_start x1(L) x_end];
Y=[0 y11(L) 0];
A=trapz(x1(L),y11(L));
n_col=n_col+1;C=cmap(n_col,:);
patch(X,Y,C,'DisplayName',sprintf('A(%d-%dHz)=%.2f',x_start,x_end,A))
end
  19 个评论
Rik
Rik 2020-10-15
You're welcome.
I doubt your legend is correct now, but that shouldn't be important for the rest of the calculation.
Rik
Rik 2020-10-15
Because A is a vector once you put it in sprintf to create the legend entry. You should also change the frequency part from '%d' to something like '%.1f'.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by