绘制满足谓词scilab的所有点

时间:2015-08-21 01:12:00

标签: plot scilab

我有函数 P ,它取两个点,如果满足某些条件则返回true,否则返回false。我想绘制满足条件的范围lx <= x <= hx, ly <= y <= hy中的所有点。如何用scilab做到这一点?

1 个答案:

答案 0 :(得分:0)

ndgridfind功能的组合非常适合这种情况。例如:

lx = 0;
hx = 10;

ly = 0;
hy = 10;

// Create x and y lists
a = linspace(lx,hx);
b = linspace(ly,hy);

// Create arrays for function evaluation on a 2D grid
[A,B] = ndgrid(a,b)

// Define your predicate as a function
function result = P(a, b)
    result = (a < b);
endfunction

// Evaluate your function for all values in A and B and as a result
// get a matrix p filled with booleans
p = P(A(:),B(:));

// Find all indices of TRUE
indices = find(p);

// Plot all points using A as x coordinate and B as y coordinate
plot(A(indices), B(indices), 'o')

// Scale the axis of the plot so that all points are visible
a=gca();
a.data_bounds = [lx,ly;hx,hy];

这将产生以下情节:

a < b