MATLAB: Multiple integration with non uniform spacing

multipleintegral

I need help to find an area intergeral of the attached file(av_val_1) with 10 columns.
where 1st column = R , second column = C, Fifth column = F(R,C).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R= avg_val_1(:,1);%first columsn = r axis
C = avg_val_1(:,2);%second column = c axis
F = avg_val_1(:,5);%fifth column = F(r,c)
I = trapz(C,trapz(R,F,2)); %area integeral of the total area. This line is wrong.
And
q = integral2(F(r,c),Rmin,Rmax,Cmin,Cmax) %area integeral of the particular area portion. This line is wrong. please see attached figure for reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Best Answer

You first need to convert the data into a grid before applying the trapz twice
x = load('avg_val_1.txt');
R = x(:,1);
C = x(:,2);
F = x(:,5);
r = linspace(min(R), max(R), 1000);
c = linspace(min(C), max(C), 1000);
[Rg, Cg] = meshgrid(r, c);
Fg = griddata(R, C, F, Rg, Cg);
result = trapz(c, trapz(r, Fg, 2));