Calculate area of a data set

1 次查看(过去 30 天)
Fanny Brenet
Fanny Brenet 2015-9-28
Dear all,
I have to find the area to the left and right of a x limit which is defined as the x corresponding to the y minimum. I join you my data set. I've used the function convhull to approximate my data. Now I need to find the area, I've tried with the trapz function but it doesn't work. And I'm not sure if it work well in both positive and negative part... Here is my code :
mat = load('hand dual.txt');
X = -mat(:,1);
%Y = mat(:,2);
Z = -mat(:,3);
hull = convhull(X,Z);
figure(1)
plot(X(hull),Z(hull));
figure(2)
plot(X,Z);
min_val = min(Z(hull));
max_val = max(Z(hull));
ind_limit_X = find(Z(hull)==min_val);
%ind_max_Y = find(Z(hull)==max_val);
new_X = X(hull);
new_Y = Z(hull);
left_X = [];
right_X = [];
X_limit = new_X(ind_limit_X);
for i=1:length(new_X)
if (new_X(i) <= X_limit)
left_X(end+1) = new_X(i);
Y_corresponding = new_Y(i);
left_area =
trapz(left_X(1:length(left_X)),Y_corresponding(1:length(left_X)));
end
if (new_X(i) >= X_limit)
right_X(end+1) = new_X(i);
Y_corresponding2 = new_Y(i);
right_area = trapz(right_X(1:length(right_X)),Y_corresponding2(1:length(right_X)));
end
end
I've the following error :
Error using permute
ORDER contains an invalid permutation index.
Error in trapz (line 43)
y = permute(y,perm);
Error in hand_pos (line 24)
left_area = trapz(left_X(1:length(left_X)),Y_corresponding(1:length(left_X)));
Thanks you a lot by advance :) If someone know a better function to find the area
Best regards,
Fanny

回答(2 个)

Subhra Saha
Subhra Saha 2015-10-1

Fanny Brenet
Fanny Brenet 2015-10-4
I've already seen that post, I tried what is proposed but it still doesn't work...
How do you think trapz treat the problem of positive and negative value ?
Thanks by advance

类别

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