How can i generate a function using this points?

If i got x=[1,3,8,25,45,23]; and y=[25,24,13,69,25,75];

댓글 수: 4

Adam
Adam 2018년 8월 29일
편집: Adam 2018년 8월 29일
What do you expect the function to do exactly?! Handle exactly that one input, returning that one output and throw an error or crash if you give it any other input?
Or do you mean you want to plot these points as x against y?
Mr. 206
Mr. 206 2018년 8월 29일
편집: Stephen23 2018년 8월 29일
This is an example where there is a y function depends on the values of x. I don't have such function, i only have points so i want a function so that i can use it for example in the below code.
% Simple curve
x = linspace(0,100,200);
y = cos(x/10)+(x/50).^2 + randn(size(x))/10;
z = smooth1q(y,[]);
plot(x,y,'r.',x,z,'k','LineWidth',2)
% axis tight square
Adam
Adam 2018년 8월 29일
There are an infinite number of functions that could take that one example input and give that output.
Mr. 206
Mr. 206 2018년 8월 29일
Okey for example if i want a polynomial function, can you help me?

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

 채택된 답변

Jan
Jan 2018년 8월 29일

1 개 추천

x = [1,3,8,25,45,23];
y = [25,24,13,69,25,75];
p = polyfit(x, y, 5)

추가 답변 (1개)

Cesar Antonio Lopez Segura
Cesar Antonio Lopez Segura 2018년 8월 29일

0 개 추천

Hi Here the solution:
% Your cloud point
x=[1,3,8,25,45,23];
y=[25,24,13,69,25,75];
% calculate a new cloud point that contain the last one
xnew = [1, 1.5 ,3,6,8,25,32,45,31,23];
ynew = interp1( x,y, xnew,'pchip' );
% plot de new values
plot(x,y,'o');hold on;plot( xnew, ynew,'r' )
% polinomios
p = interp1( x,y,'pchip' );

댓글 수: 5

Mr. 206
Mr. 206 2018년 8월 30일
Thanks for reply. Using this 'pchip' command gives an error "error: interp1: discontinuities not supported for method 'pchip'"
What is your MATLAB version ?
Your cloud point
x=[1,3,8,25,45,23]; y=[25,24,13,69,25,75];
[xtointerpol indx ] = sort(x);
ytointerpol = y(indx);
% calculate a new cloud point that contain the last one
ynew = interp1( xtointerpol,ytointerpol, xtointerpol, 'pchip' );
% plot de new values
close all
% plot(x,y,'+b');hold on;plot( xnew, ynew,'--or' )
plot(x,y,'+b');hold on;
plot( xtointerpol, ynew,'--or' )
% polinomios
p = pchip( xtointerpol,ytointerpol );
Mr. 206
Mr. 206 2018년 8월 30일
Great, Now it is working. Thanks :)
Mr. 206
Mr. 206 2018년 8월 30일
If the x values are not monotonic, then is there any way to handle this?
You can define x values in ascending order with sort.
Then you can order de y values.
[xtointerpol indx ] = sort(x);
ytointerpol = y(indx);

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

카테고리

도움말 센터File Exchange에서 Cloud Integrations에 대해 자세히 알아보기

태그

질문:

2018년 8월 29일

댓글:

2018년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by