public static double GetDoubleFromWorkspace(string doubleName) { object O = null; #if MATLAB MATLAB.GetWorkspaceData(doubleName, "base", out O); #endif return((double)O); }
public object[] getQ(MLApp.MLApp matlab) { object qUL; object qL; object f_center; object s21; matlab.GetWorkspaceData("Q_L", "base", out qL); matlab.GetWorkspaceData("Q_UL", "base", out qUL); matlab.GetWorkspaceData("f_center", "base", out f_center); matlab.GetWorkspaceData("s21", "base", out s21); object[] result = { qL, qUL, f_center, s21 }; return(result); }
public object[] getMLData(MLApp.MLApp matlab) { object manual_means; object manual_stdevs; object auto_means; object auto_stdevs; object sections; object indices; object a; matlab.GetWorkspaceData("manual_means", "base", out manual_means); matlab.GetWorkspaceData("manual_stdevs", "base", out manual_stdevs); matlab.GetWorkspaceData("auto_means", "base", out auto_means); matlab.GetWorkspaceData("auto_stdevs", "base", out auto_stdevs); matlab.GetWorkspaceData("sections", "base", out sections); matlab.GetWorkspaceData("indices", "base", out indices); matlab.GetWorkspaceData("a", "base", out a); object[] result = { manual_means, manual_stdevs, auto_means, auto_stdevs, sections, indices, a }; return(result); }
public static double[,] GetMatrix(string matlabname, string workspacename = WORKSPACENAME) { ML.GetWorkspaceData(matlabname, workspacename, out object r); return((double[, ])r); }
/// <summary> /// Grab data from the workspace. /// </summary> /// <param name="name"> the name of the variable in the Matlab workspace.</param> /// <param name="workspace"> the workspace name, (generally "base")</param> /// <param name="val"> out the object from Matlab.</param> public static void GetWorkspaceData(string name, string workspace, out object val) { matlab.GetWorkspaceData(name, workspace, out val); }
static void Main(string[] args) { // create pipe client to receive data from unity server NamedPipeClientStream pipeclient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut); Console.WriteLine("Connecting to server ......"); pipeclient.Connect(); Console.WriteLine("Server connected"); // use COM interface to invoke Matlab function MLApp.MLApp matlab = new MLApp.MLApp(); int width, height; /* * width = pipeclient.ReadByte() * 256; * width += pipeclient.ReadByte(); * height = pipeclient.ReadByte() * 256; * height += pipeclient.ReadByte(); */ width = 1280;// Here we use default screen size height = 600; // Get background data from preload workspace data object background = null; matlab.Execute("load('background.mat');"); matlab.GetWorkspaceData("bb2", "base", out background); // Start transfer while (pipeclient.IsConnected) { int result = 0;// save distance result Thread.Sleep(500); int size = width * height; byte[] imageRed = new byte[size]; byte[] imageGreen = new byte[size]; byte[] imageBlue = new byte[size]; pipeclient.Read(imageRed, 0, size); pipeclient.Read(imageGreen, 0, size); pipeclient.Read(imageBlue, 0, size); // when transfer data is null end transfer for (int i = 0; i < 100; i++) { if (imageRed[i] == 0) { result++; } } if (imageRed == null || imageRed.Length == 0 || result == 100) { break; } // Get transfer data use Matlab to calculate distance object resultOfMatlab = null; matlab.Feval("getdistance", 1, out resultOfMatlab, imageRed, imageGreen, imageBlue, height, width, background); object[] res = resultOfMatlab as object[]; int distance = Convert.ToInt32(res[0]); Console.WriteLine("result = " + distance); // Transfer back the distance to Unity server pipeclient.WriteByte((byte)(distance / 256)); pipeclient.WriteByte((byte)(distance & 255)); pipeclient.Flush(); } pipeclient.Close(); }
public object GetVariable(string varName) { _mlapp.GetWorkspaceData(varName, "base", out var data); return(data); }