# I have two set data and I want to calculate the area in different x and plot the area curve with respect to X

2 visualizzazioni (ultimi 30 giorni)
Misi il 10 Ott 2023
Commentato: Star Strider il 10 Ott 2023
For example
x=[1 1.5 1.7 2 2.2 2.6 2.8];
y=[0 2 6 7 8 10 5];
Now I wanted to plot the area under these data with respect to x
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 10 Ott 2023
Perhaps this —
x=[1 1.5 1.7 2 2.2 2.6 2.8];
y=[0 2 6 7 8 10 5];
int_y = cumtrapz(x, y);
figure
plot(x, y, 'DisplayName','Data')
hold on
plot(x, int_y, 'DisplayName','Cumulative Integral of ‘y’')
hold off
grid
xlabel('x')
ylabel('y')
legend('Location','NW')
.
##### 2 CommentiMostra NessunoNascondi Nessuno
Misi il 10 Ott 2023
Thank you
Star Strider il 10 Ott 2023
As always, my pleasure!

Accedi per commentare.

### Più risposte (1)

dpb il 10 Ott 2023
x=[1 1.5 1.7 2 2.2 2.6 2.8];
y=[0 2 6 7 8 10 5];
A=trapz(x,y); % the total area (one number)
a=cumtrapz(x,y); % each segment area (last is total)
[A a(end)] % show above is so...
ans = 1×2
9.8500 9.8500
plot(x,a,'-x') % plot the cumulative area, show where the data points are
See trapz and cumtrapz for further details...
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Misi il 10 Ott 2023
thank you

Accedi per commentare.

### Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by