MATLAB: How to distribute random points in some lines MATLABpoissonpoisson point process The follow code is a poisson line process code. https://github.com/hpaulkeeler/posts/blob/master/PoissonLine/PoissonLine.m I want to distibute the random points in the lines. The point process is not specified. The point process is a unifrom random or a poisson point process. Best Answer %% Striaght line L = rand(2,2) ; P1 = L(1,:) ; P2 = L(2,:) ; % Get slope and y intercept P = polyfit(L(:,1),L(:,2),1) ; m = P(1) ; c = P(2) ; % Get random points a = min(L(:,1)) ; b = max(L(:,1)) ; N = 20 ; x = (b-a)*rand(N,1)+a ;y = m*x+c ; figurehold onplot(L(:,1),L(:,2),'r')hold onplot(x,y,'*k') Related SolutionsMATLAB: How to distribute users uniformaly inside rectangle L = 1 ; % length of the rectnagle B = 2 ; % breadth of the rectangle Rect = [ 0 0 ; L 0 ; L B ; 0 B ; 0 0] ;N = 1000 ;a1 = 0;b1 = L;x = (b1-a1).*rand(N,1) + a1;a2 = 0;b2 = B;y = (b2-a2).*rand(N,1) + a2;plot(Rect(:,1),Rect(:,2),'r')hold onplot(x,y,'.b') MATLAB: How to draw this graph Read about xticks for labelling x1, x2 along the axes. I have taken random points for plotting. You can take your required points to plot striaght line and the curve. % Striaght line L = rand(2,2) ; % Curve passing through above two points p = polyfit(L(:,1),L(:,2),3) ; xi = linspace(min(L(:,1)),max(L(:,1))) ; yi = polyval(p,xi) ; %plotfigurehold onplot(L(:,1),L(:,2),'r')plot(xi,yi,'b')xlabel('x')ylabel('y')% Add text text(mean(L(:,1)),mean(L(:,2))+0.02,'p(x)','FontSize',20)text(mean(xi),mean(yi)-0.02,'f(x)','FontSize',20) Related QuestionCreate random values between two decimal valuesHow to plot random points in airfoil wingRandom number using poisson process
Best Answer