2
$\begingroup$

I have a two-dimensional array in C# (using .Netlink)

double[][] rho

The values of the array change dynamically as it represents some process in time.

I have tested the following code to make sure 3D Graphics will work normally:

try
       {
           MathKernel k = new MathKernel(ml);
           k.CaptureGraphics = true;
           k.GraphicsFormat = "JPEG";
             string command = @"Show[ListPointPlot3D[Table[Sin[j^2 + i], {i, 
0, 3, 0.1}, {j, 0, 3, 0.1}]]]";
           k.Compute(command);
           pictureBox1.Image = k.Graphics[0];
       }
       catch (Exception ee)
       {
           MessageBox.Show(ee.Message);
       }

How can I change the command variable, so I could call ListPointPlot3D for the array in question? Thank you in advance?

$\endgroup$
1
$\begingroup$

Perhaps someone will come up with something more concise.

try
       {
           double[][] rho = new double[4][] { new double[] { 0.0, 0.8, -0.8, 0.4 }, new double[] { 0.8, 0.9, -1.0, -0.5 }, new double[] { 0.9, 0.1, -0.3, -1.0 }, new double[] { 0.1, -0.8, 0.7, -0.5 } };

           var res = rho
               .Where(inner => inner != null) // Cope with uninitialised inner arrays.
               .Select(inner => inner.ToList()) // Project each inner array to a List<double>
               .ToList(); // Materialise the IEnumerable<List<double>> to List<List<double>>

           string str = "{";
           foreach (var a in res)
           {
               str += "{";
               foreach (double b in a)
                   str += b.ToString() + ", ";
               str += "}, ";
           }
           str += "}";
           str = str.Replace(", }", "}");

           MathKernel k = new MathKernel(ml);
           k.CaptureGraphics = true;
           k.GraphicsFormat = "JPEG";
           string command = string.Format("{0}{1}{2}", "Show[ListPointPlot3D[", str, "]]");
           k.Compute(command);
           pictureBox1.Image = k.Graphics[0];
       }
       catch (Exception ee)
       {
           MessageBox.Show(ee.Message);
       }
$\endgroup$
  • $\begingroup$ I mark this as an accepted. This code works perfectly for me even for the array with more than 100 nodes. Thank you! $\endgroup$ – Тимофей Ломоносов Nov 3 '17 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.