for循环中的Scilab散点图
Scilab scatter plot in a for loop
我正在尝试在 for 循环中绘制散点图,其中我只绘制最后一点。
但是当查看我绘制的点时,它们是从我的等式中获得的点。
如何才能只获取和绘制最后的点?
代码如下:
m=1000
z=4000
T=200
pr=101325
sigma=0.24
cc=sigma*10^(-18)
lambda=((1.38*10^(-23)*T)/(sqrt(2)*pr*cc))
p=%pi*2
for I=1:z
theta=(grand(m,1,"unf",0,p));
cx= cumsum(lambda*cos(theta));
cy= cumsum(lambda*sin(theta));
scatter((cx,cy))
xlabel(["x"]);
ylabel("y");
title("Partilcle Distribution");
end
如果您想要在每个循环中获取 cx
和 cy
的最后一个值,一种选择是创建新数组来存储这些值并将它们绘制在循环之外,像这样:
...
x = zeros(1,z); //row matrix filled with zeros
y = zeros(1,z); //row matrix filled with zeros
for I=1:z
theta = grand(m,1,"unf",0,p);
cx = cumsum(lambda*cos(theta));
cy = cumsum(lambda*sin(theta));
//overwriting values
x(I) = cx($); //the dollar sign ($) returns the last element
y(I) = cy($); //of a row or a column in a matrix
end
scatter(x,y);
xlabel("x");
ylabel("y");
title("Partilcle Distribution");
我正在尝试在 for 循环中绘制散点图,其中我只绘制最后一点。 但是当查看我绘制的点时,它们是从我的等式中获得的点。
如何才能只获取和绘制最后的点?
代码如下:
m=1000
z=4000
T=200
pr=101325
sigma=0.24
cc=sigma*10^(-18)
lambda=((1.38*10^(-23)*T)/(sqrt(2)*pr*cc))
p=%pi*2
for I=1:z
theta=(grand(m,1,"unf",0,p));
cx= cumsum(lambda*cos(theta));
cy= cumsum(lambda*sin(theta));
scatter((cx,cy))
xlabel(["x"]);
ylabel("y");
title("Partilcle Distribution");
end
如果您想要在每个循环中获取 cx
和 cy
的最后一个值,一种选择是创建新数组来存储这些值并将它们绘制在循环之外,像这样:
...
x = zeros(1,z); //row matrix filled with zeros
y = zeros(1,z); //row matrix filled with zeros
for I=1:z
theta = grand(m,1,"unf",0,p);
cx = cumsum(lambda*cos(theta));
cy = cumsum(lambda*sin(theta));
//overwriting values
x(I) = cx($); //the dollar sign ($) returns the last element
y(I) = cy($); //of a row or a column in a matrix
end
scatter(x,y);
xlabel("x");
ylabel("y");
title("Partilcle Distribution");