Question

I'm stucked on plotting a surface in ILSurface. The scenario is the following:

Plot an irregular grid:

float[] x = new float[sizeX]; // filled with timestamps

float[] y = new float[sizeY]; // filled with values

float[,] z = new float[sizeX, sizeY]; // filled with values mapped by [x,y]

ILInArray<float> inX = ILMath.array(x);
ILInArray<float> inY = ILMath.array(y);
ILInArray<float> inZ = ILMath.meshgrid(inX * inY, inX, inY);

// how do i fill the inZ with z[,]?

ILRetArray<float> outMesh = ILMath.meshgrid(inX, inY, inZ, null, null);

plotCube.Add(new ILSurface(outMesh, null, null, null, null));

// plotCube already attached to the scene, and the scene with the ILPanel

ilPanel1.Refresh(); 

Want to map this in a array so it can be plot on a ILSurface.

I've tried out some ILMath.meshgrid to fill the ILInArray<double> ZXYArray with no success.

Hope i've been clear. Any help welcome.

Thanks.

Was it helpful?

Solution

Here comes a simple example how to plot a 3D surface with ILNumerics and provide custom X and Y ranges. It expects the regular setup of a Windows.Forms application with ILNumerics:

private void ilPanel1_Load(object sender, EventArgs e) {
    // define X and Y range
    ILArray<float> X = ILMath.vec<float>(-10.0, 0.1, 10.0);
    ILArray<float> Y = ILMath.vec<float>(-6.0, 0.1, 6.0);

    // compute X and Y coordinates for every grid point
    ILArray<float> YMat = 1; // provide YMat as output to meshgrid
    ILArray<float> XMat = ILMath.meshgrid(X, Y, YMat); // only need mesh for 2D function here

    // preallocate data array for ILSurface: X by Y by 3
    // Note the order: 3 matrix slices of X by Y each, for Z,X,Y coordinates of every grid point
    ILArray<float> A = ILMath.zeros<float>(Y.Length, X.Length, 3); 

    // fill in Z values (replace this with your own function / data!!)
    A[":;:;0"] = ILMath.sin(XMat) * ILMath.sin(YMat) * ILMath.exp(-ILMath.abs(XMat * YMat) / 5);
    A[":;:;1"] = XMat; // X coordinates for every grid point
    A[":;:;2"] = YMat; // Y coordinates for every grid point

    // setup the scene + plot cube + surface 
    ilPanel1.Scene = new ILScene() {
        new ILPlotCube(twoDMode: false) {
            new ILSurface(A) {
                UseLighting = true, 
                Children = { new ILColorbar() }
            }
        }
    };
}

It produces the following result:

ILNumerics Surface Plot

Here is the same example as interactive Web Component.

Note the order the grid point coordinates are defined. See the documentation here: http://ilnumerics.net/surface-plots.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top