How to find the area if the traced are in the graph graph?

조회 수: 2 (최근 30일)
John Reige Bendijo
John Reige Bendijo 2020년 7월 8일
댓글: John Reige Bendijo 2020년 7월 9일
Good day, I am trying to calculate the area of the traced area shown in the graph. This is my Matlab code.
y = [40 40 30 20 15 15 22 33 46 56 48 26 20 20];
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14];
plot(x,y,'*')
ylim([0 60])
annotation('line',[0.7383 0.7969],[0.7576 0.4664])
annotation('line',[0.6759 0.7355],[0.873 0.7621])
annotation('line',[0.6294 0.6841],[0.7335 0.871])
annotation('line',[0.5742 0.6305],[0.5607 0.7379])
annotation('line',[0.5205 0.5747],[0.4112 0.5672])
annotation('line',[0.4078 0.5184],[0.3184 0.4126])
annotation('line',[0.8529 0.9074],[0.3829 0.3829])
annotation('line',[0.7953 0.8516],[0.4641 0.382])
annotation('line',[0.4028 0.9047],[0.3178 0.3769])
And is there a way to color the traced area like this one
Thank you so much.

채택된 답변

darova
darova 2020년 7월 8일
  • select points you need
  • use trapz or polyarea
y = [40 40 30 20 15 15 22 33 46 56 48 26 20 20];
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14];
ii = [5 7:length(x) 5];
plot(x,y,'*')
line(x(ii),y(ii))
trapz(x(ii),y(ii))
polyarea(x(ii),y(ii))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by