箭頭→箭頭 matlab畫圖

redufa發表於2024-09-19

image


close all
t=linspace(-4,4,1000);

pdf=normpdf(t)
cdf=normcdf(t)
plot(t,pdf,"b",'LineWidth', 2);

hold on



plot(t,cdf,'k','LineWidth', 3);


N=5
y=rand(N,1);
x=zeros(N,1)-4;
scatter(x,y,60,'r','filled')


% 繪製隨機數的直方圖  


title('標準正態分佈');  
xlabel('值');  
ylabel('機率密度');

x2=norminv(y);

y2=zeros(N,1);

scatter(x2,y2,80,'*')


p=gca().Position

for i=1:N
 xx3=p(1)+p(3)*(x2(i)+4)/8


yy3=p(2)+p(4)*y(i)/1.5;


x3=[p(1),xx3];

y3=[yy3,yy3];

arrow=annotation('textarrow',x3,y3,'Color','red')


x4=[xx3,xx3]
y4=[  yy3 p(2)]

arrow=annotation('textarrow',x4,y4,'Color','red')

% 
% set(arrow, 'LineColor', 'r'); % 設定為紅色  

end

legend('密度函式f(t)','累計分佈F(t)',"[0,1]均勻分佈");  


ylim([0,1.5])
xlim([-4,4])

hold off

相關文章