I am trying to create random points around a defined polynomial.
The polynomial is created with defined points.
I have the polynom but I cannot creat the random points. Can someone please help me?
x_poly = [700 750 730 630 700 745 830 765 700];
y_poly = [0 266 570 780 1150 1300 1580 1880 2400];
%Create Polynom based on used point coordinates
t = (1:length(x_poly))';
Px = polyfit(t,x_poly,5);
Py = polyfit(t,y_poly,5);
ti = linspace(min(t),max(t));
plot(x_poly,y_poly,'o',polyval(Px,ti),polyval(Py,ti),'-')

 採用された回答

Stefano Ferrari
Stefano Ferrari 2021 年 1 月 5 日

0 投票

Just managed to do it:
x_poly = [700 750 730 630 700 745 830 765 700];
y_poly = [0 266 570 780 1150 1300 1580 1880 2400];
t = (1:length(x_poly));
Px = polyfit(t,x_poly,7);
Py = polyfit(t,y_poly,7);
ti = linspace(min(t),max(t),600);
x=polyval(Px,ti+rand(1,600));
y=polyval(Py,ti+rand(1,600));
scatter(x,y)

その他の回答 (1 件)

KSSV
KSSV 2021 年 1 月 5 日

0 投票

x_poly = [700 750 730 630 700 745 830 765 700];
y_poly = [0 266 570 780 1150 1300 1580 1880 2400];
%Create Polynom based on used point coordinates
t = (1:length(x_poly)); %<--- no transpose
Px = polyfit(t,x_poly,5);
Py = polyfit(t,y_poly,5);
ti = linspace(min(t),max(t));
plot(x_poly,y_poly,'o',polyval(Px,ti),polyval(Py,ti),'-')

3 件のコメント

Stefano Ferrari
Stefano Ferrari 2021 年 1 月 5 日
That does not change anything
KSSV
KSSV 2021 年 1 月 5 日
Your error is solved...that's what I did. What exactly you want ?
Stefano Ferrari
Stefano Ferrari 2021 年 1 月 5 日
I want to scatter points around the polynom (see picture).

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by