Interpolation and curve line
조회 수: 7 (최근 30일)
이전 댓글 표시
Greetings,
I have the following data for x and y and I would like to interpolate for the y values along the x from -5 to 5 and I also would like to generage an ellipse curve
W4_x=[-5 -4 -3 -2 -1 0 1 2 3 4 5];
W4_y=[0 .254 .508 .762 1.016 1.27 1.016 .762 .508 .254 0];
%%%% I have tried the following codings, but they do not work%%%
%%% CODING 1%%%
%%p=polyfit(W4_x, W4_y, 100);
%%v=polyval(p, W4_x);
%%%CODING 2%%%
%n=100;
%W4_intx=linspace(min(W4_x), max (W4_x), n);
%W4_inty=interp1(W4_x, W4_y, W4_intx, 'spline');
댓글 수: 0
답변 (1개)
KSSV
2020년 10월 21일
x=[-5 -4 -3 -2 -1 0 1 2 3 4 5];
y=[0 .254 .508 .762 1.016 1.27 1.016 .762 .508 .254 0];
% Interpolation
xi = linspace(min(x),max(x),100) ;
yi = interp1(x,y,xi) ;
% Fit a quadtratic curve
p = polyfit(xi,yi,2) ;
% plot
plot(x,y,'.r')
hold on
plot(xi,yi,'b')
plot(xi,polyval(p,xi),'k')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!