MATLAB Answers

## how can i Calculate area of plotted data using trapz in matlab?

Asked by jasper kansiime

### jasper kansiime (view profile)

on 16 Sep 2018
Latest activity Commented on by jasper kansiime

### jasper kansiime (view profile)

on 17 Sep 2018
Accepted Answer by Dimitris Kalogiros

### Dimitris Kalogiros (view profile)

have data from csv file. i want to calculate area under plot using trapz but im not sure if trapz is calculating from zero on y-axis as a reference or the starting point of x&y-axes. How can i calculate this area subtracting region below minimum point?
code is below data=csvread('test_1.csv'); new_data=smoothdata(data); x_col1=new_data(:,1); y_col2=new_data(:,2); figure('Name','Smoothed_waveform') plot(x_col1,y_col2,'r')
title('Induced emf') xlabel('Time (s)') ylabel('Amplitude')
grid on grid minor
max_y= max(new_data(:,2))% maximum value of signal min_y= min(new_data(:,2))% minimum value of signal amplitude= (max_y-min_y) %amplitude of signal area_2 = trapz(new_data(:,1),new_data(:,2))
graph #### 0 Comments

Sign in to comment.

## 1 Answer

Answer by Dimitris Kalogiros

### Dimitris Kalogiros (view profile)

on 16 Sep 2018
Edited by Dimitris Kalogiros

### Dimitris Kalogiros (view profile)

on 16 Sep 2018
Accepted Answer

Before using trapz, do the following
new_data(:,2)=new_data(:,2)-min(new_data(:,2));
this shifts all of your graph upwards, so minimum value would be on xx' axis.

jasper kansiime

### jasper kansiime (view profile)

on 17 Sep 2018
yes. this is better. Thanks so much. Results are as expected now.

Sign in to comment.