how to find the length of interpolated graph?

조회 수: 3 (최근 30일)
Aidan Palermo
Aidan Palermo 2021년 11월 16일
댓글: Star Strider 2021년 11월 16일
I created a graph that would go through these specific x and y values using the interp1 function. now I can't figure out how to find the length of the graph. I pasted the code for how I was trying to find the length but I recieve an error message saying Array indices must be positive integers or logical values.
x=[0 .6 1 1.3 1.4 1.8 2];
y=[0 .4 1.2 1.7 .8 1.2 1.4];
xq=0:.1:2;
vq=interp1(x,y,xq,'spline');
plot(x,y,'co',xq,vq,'k*--')
i=0:.1:2;
l=sqrt(x(i)^2+y(i).^2)

채택된 답변

Star Strider
Star Strider 2021년 11월 16일
편집: Star Strider 2021년 11월 16일
The length of the graph (interpolated values) is the length of the interpolation vector ‘xq’ and here is a (1x21)
vector.
x=[0 .6 1 1.3 1.4 1.8 2];
y=[0 .4 1.2 1.7 .8 1.2 1.4];
xq=0:.1:2;
vq=interp1(x,y,xq,'spline')
vq = 1×21
0 0.2431 0.3724 0.4203 0.4193 0.4017 0.4000 0.4466 0.5738 0.8142 1.2000 1.6951 1.9883 1.7000 0.8000 0.3325 0.3947 0.7595 1.2000 1.4892 1.4000
plot(x,y,'co',xq,vq,'k*--')
i=0:.1:2;
for ii = 1:numel(x)
l(ii)=sqrt(x(ii)^2+y(ii).^2);
end
l
l = 1×7
0 0.7211 1.5620 2.1401 1.6125 2.1633 2.4413
EDIT — (16 Nov 2021 at 2:48)
The function necessary to find the size of ‘vq’ is size
vq_size = size(vq)
vq_size = 1×2
1 21
.
  댓글 수: 6
Aidan Palermo
Aidan Palermo 2021년 11월 16일
that worked, thank you.
Star Strider
Star Strider 2021년 11월 16일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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