求一小程序中的一小句解释:。

clear all;
%设置超几何分布的参数
M=1000;
K=50;
n=20;
% 产生len个随机数
len=5;
y1=hygernd(M,K,n,[1 len]);
%产生P*Q的矩阵
P=3;
Q=4;
y2=hygernd(M,K,n,P,Q)
%显示超几何分布的柱状图
M=1000;
y3=hygernd(M,K,n,[1,M]);
figure(1);
t=0:1:max(y3);
hist(y3,t);
axis([0 max(y3) 0 500]);
xlabel('取值');
ylabel('计数值') 望大虾解释下 在好多程序中 我都看到 figure(1) 或 figure 不知这句什么意思???? 在网上搜了好久 一直没有答 案!!!

 采纳的回答

kedew
kedew 2022-11-22

0 个投票

你仔细读读 help,你会发现 figure 和 figure(h) 是会有不同的。首先,figure 是一个函数,如果没有输入参数(h),就是默认打开一个新的(空的)图形对象,而 figure(h) 可能有多钟意思:
1. 当图形对象 h 已经存在了, figure(h) 设置为默认的当前图形 (这在画了多幅图时有用)
2. 当图形对象 h 不存在,且 h 是一个整数,如 1,2,3 。。 就会产生一个新的图形对象,且图形句柄为 h
下面举个例子,以示区别:
figure(1)
plot(1:10)
figure(2)
stem(1:10)
figure(1)
hold on
plot((1:10).^2)
如果明白了我上面说的,就应该知道为什么最后一句抛物线是画在了第一幅图里

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!