Question

I have used this code:

    private void ilPanel1_Load(object sender, EventArgs e)
    {    using (ILScope.Enter())
        {
            ILArray<float> X = new float[] { 0, 0, 1, 1, 2.5F, -2.6F, 5, 9, 1, 38 };
            ILArray<float> Y = new float[] { 1, 0, 1, 0, 1.5F,  0.5F, 5, 9, 1, 39 };
            ILArray<float> Z = new float[] { 0, 0, 1, 1, 0.4F, -0.2F, 5, 9, 1, 39 };
            X = X.Reshape(2,5);
            Y = Y.Reshape(2,5);
            Z = Z.Reshape(2,5);
            ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
                new ILSurface(Z, colormap: Colormaps.Cool) {
                    Colors = 1.4f  ,Children = { new ILColorbar() }
                }
            });
        }
    }

This produces:

enter image description here

However I checked this question and tried to adapt deprecated ILnumerics solution (as I did not find other c# code), but still do not get it, every coordinate (Z,X and Y) corresponds to one slice (m x n) in the array. So it is necesarry to reshape data.

this part is the problem:

            X = X.Reshape(2,5);
            Y = Y.Reshape(2,5);
            Z = Z.Reshape(2,5);

If I do not give correct size, program fails, so in example I have 10 elements on each vector, so when resahping I would put 2,5 which multiplied are 10?...

What about case I have 11 elements as if I put 2,5 on reshape I get error?

What to do?

I have tried using X = X.Reshape(11); but It fails... if I use X = X.Reshape(10); it just do not draw anything

Was it helpful?

Solution

surfaces plot meshes. one must provide a mesh in order to give the surface the chance to understand how to connect the points, which points are meant to be neighbors.

the reshape should not be a problem since the original data must represent the points for a mesh/matrix anyway. so the reshape to that matrix will certainly work.

reshape(10) creates a vector of length 10. since vectors do represent a line at most but not an area - nothing is drawn. remember: surfaces draw meshes or matrices.

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