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개)

Fanny Brenet
Fanny Brenet 2015년 10월 4일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2015년 9월 28일

답변:

2015년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by