Calculate area of a data set
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (2)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!