From 5a43ba23d0f59d178a4e7cb1321c8f3c6cf417d5 Mon Sep 17 00:00:00 2001 From: Mus M Date: Fri, 27 Oct 2017 09:55:01 -0400 Subject: [PATCH 1/7] Remove references to deprecated `@matlab` macro --- README.md | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/README.md b/README.md index d7d79ef..3f0ba0f 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,6 @@ This example will create a MAT file called ``test.mat``, which contains six MATL To evaluate expressions in MATLAB, one may open a MATLAB engine session and communicate with it. There are three ways to call MATLAB from Julia: - The `mat""` custom string literal allows you to write MATLAB syntax inside Julia and use Julia variables directly from MATLAB via interpolation -- The `@matlab` macro, in combination with `@mput` and `@mget`, translates Julia syntax to MATLAB - The `mxcall` function calls a given MATLAB function and returns the result *Note:* There can be multiple (reasonable) ways to convert a MATLAB variable to Julia array. For example, MATLAB represents a scalar using a 1-by-1 matrix. Here we have two choices in terms of converting such a matrix back to Julia: (1) convert to a scalar number, or (2) convert to a matrix of size 1-by-1. @@ -253,51 +252,6 @@ mat""" As with ordinary string literals, you can also interpolate whole Julia expressions, e.g. `mat"$(x[1]) = $(x[2]) + $(binomial(5, 2))"`. -##### The `@matlab` macro - -The example above can also be written using the `@matlab` macro in combination with `@mput` and `@mget`. - -```julia -using MATLAB - -x = linspace(-10., 10., 500) -@mput x # put x to MATLAB's workspace -@matlab plot(x, sin(x)) # evaluate a MATLAB function - -y = linspace(2., 3., 500) -@mput y -@matlab begin - u = x + y - v = x - y -end -@mget u v -@show u v -``` - -###### Caveats of @matlab - -Note that some MATLAB expressions are not valid Julia expressions. This package provides some ways to work around this in the ``@matlab`` macro: - -```julia - # MATLAB uses single-quote for strings, while Julia uses double-quote. -@matlab sprintf("%d", 10) # ==> MATLAB: sprintf('%d', 10) - - # MATLAB does not allow [x, y] on the left hand side -x = linspace(-5.0, 5.0, 100) -y = x -@mput x y -@matlab begin - (xx, yy) = meshgrid(x, y) # ==> MATLAB: [xx, yy] = meshgrid(x, y) - mesh(xx, yy, xx.^2 + yy.^2) -end -``` - -While we try to cover most MATLAB statements, some valid MATLAB statements remain unsupported by ``@matlab``. For this case, one may always call the ``eval_string`` function, as follows - -```julia -eval_string("[u, v] = myfun(x, y);") -``` - ##### `mxcall` You may also directly call a MATLAB function on Julia variables using `mxcall`: From 07a75902b1221f395eaf09ce57ff9c14983295c8 Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 31 Oct 2017 10:34:25 -0400 Subject: [PATCH 2/7] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 3f0ba0f..69ccbe4 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,19 @@ mat""" As with ordinary string literals, you can also interpolate whole Julia expressions, e.g. `mat"$(x[1]) = $(x[2]) + $(binomial(5, 2))"`. +##### `eval_string` + +You may also use the `eval_string` function to evaluate MATLAB code as follows + ```julia +eval_string("a = sum([1,2,3])") +``` + +The `eval_string` also takes an optional argument that specifies which MATLAB session to evaluate the code in, e.g. +```julia +s = MSession() +eval_string(s, "a = sum([1,2,3])") +``` + ##### `mxcall` You may also directly call a MATLAB function on Julia variables using `mxcall`: From 2f08e76c720cf611f6f768ce296357db6c77572f Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 31 Oct 2017 11:12:20 -0400 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69ccbe4..5d8beea 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ The `eval_string` also takes an optional argument that specifies which MATLAB se s = MSession() eval_string(s, "a = sum([1,2,3])") ``` - + ##### `mxcall` You may also directly call a MATLAB function on Julia variables using `mxcall`: From 8cc29d1a80e906b269b851cc2dab0ae3553efa1f Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 31 Oct 2017 22:59:26 -0400 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d8beea..9a5b6d0 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ You may also use the `eval_string` function to evaluate MATLAB code as follows eval_string("a = sum([1,2,3])") ``` -The `eval_string` also takes an optional argument that specifies which MATLAB session to evaluate the code in, e.g. +The `eval_string` function also takes an optional argument that specifies which MATLAB session to evaluate the code in, e.g. ```julia s = MSession() eval_string(s, "a = sum([1,2,3])") From 04298b857293eb3c795f1be99fa2e1ba3be29b30 Mon Sep 17 00:00:00 2001 From: Mus M Date: Wed, 1 Nov 2017 11:42:51 -0400 Subject: [PATCH 5/7] Update README.md --- README.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a5b6d0..16784ad 100644 --- a/README.md +++ b/README.md @@ -228,8 +228,12 @@ This example will create a MAT file called ``test.mat``, which contains six MATL To evaluate expressions in MATLAB, one may open a MATLAB engine session and communicate with it. There are three ways to call MATLAB from Julia: - The `mat""` custom string literal allows you to write MATLAB syntax inside Julia and use Julia variables directly from MATLAB via interpolation +- The `eval_string` evaluate a string containing MATLAB expressions (typically used with the helper macros `@mget` and `@mput` - The `mxcall` function calls a given MATLAB function and returns the result +In general, the `mat""` custom string literal is the preferred method to interact with the MATLAB engine. In addition there are helper macros `@mget`, `@mput` to aid in translating variables from and to Julia and MATLAB + + *Note:* There can be multiple (reasonable) ways to convert a MATLAB variable to Julia array. For example, MATLAB represents a scalar using a 1-by-1 matrix. Here we have two choices in terms of converting such a matrix back to Julia: (1) convert to a scalar number, or (2) convert to a matrix of size 1-by-1. ##### The `mat""` custom string literal @@ -261,8 +265,10 @@ eval_string("a = sum([1,2,3])") The `eval_string` function also takes an optional argument that specifies which MATLAB session to evaluate the code in, e.g. ```julia -s = MSession() -eval_string(s, "a = sum([1,2,3])") +julia> s = MSession(); +julia> eval_string(s, "a = sum([1,2,3])") +a = + 6 ``` ##### `mxcall` @@ -278,6 +284,28 @@ xx, yy = mxcall(:meshgrid, 2, x, y) ``mxcall`` puts the input arguments to the MATLAB workspace (using mangled names), evaluates the function call in MATLAB, and retrievs the variable from the MATLAB session. This function is mainly provided for convenience. However, you should keep in mind that it may incur considerable overhead due to the communication between MATLAB and Julia domain. +##### `@mget` and `@mput` + +The macro `@mget` can be used to extract the value of a MATLAB variable into Julia + +```julia +julia> mat"a = 6" +julia> @mget a +6.0 +``` + +The macro `@mput` can be used to translate a Julia variable into MATLAB + +```julia +julia> x = [1,2,3] +julia> @mput x +julia> eval_string("y = sum(x)") +julia> @mget y +6.0 +julia> @show y +a = 63.0 +``` + #### Viewing the MATLAB Session (Windows only) To open an interactive window for the MATLAB session, use the command `show_msession()` and to hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.* From 6d7d953869667430a32a2789f37aace35808fb81 Mon Sep 17 00:00:00 2001 From: Mus M Date: Thu, 2 Nov 2017 01:02:29 -0400 Subject: [PATCH 6/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16784ad..8d20609 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ To evaluate expressions in MATLAB, one may open a MATLAB engine session and comm - The `eval_string` evaluate a string containing MATLAB expressions (typically used with the helper macros `@mget` and `@mput` - The `mxcall` function calls a given MATLAB function and returns the result -In general, the `mat""` custom string literal is the preferred method to interact with the MATLAB engine. In addition there are helper macros `@mget`, `@mput` to aid in translating variables from and to Julia and MATLAB +In general, the `mat""` custom string literal is the preferred method to interact with the MATLAB engine. *Note:* There can be multiple (reasonable) ways to convert a MATLAB variable to Julia array. For example, MATLAB represents a scalar using a 1-by-1 matrix. Here we have two choices in terms of converting such a matrix back to Julia: (1) convert to a scalar number, or (2) convert to a matrix of size 1-by-1. From 2c023388b93ce79aaede17f8777cfb4a5984f5c7 Mon Sep 17 00:00:00 2001 From: Mus M Date: Thu, 2 Nov 2017 01:03:14 -0400 Subject: [PATCH 7/7] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 8d20609..a15472d 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,6 @@ To evaluate expressions in MATLAB, one may open a MATLAB engine session and comm In general, the `mat""` custom string literal is the preferred method to interact with the MATLAB engine. - *Note:* There can be multiple (reasonable) ways to convert a MATLAB variable to Julia array. For example, MATLAB represents a scalar using a 1-by-1 matrix. Here we have two choices in terms of converting such a matrix back to Julia: (1) convert to a scalar number, or (2) convert to a matrix of size 1-by-1. ##### The `mat""` custom string literal @@ -287,7 +286,6 @@ xx, yy = mxcall(:meshgrid, 2, x, y) ##### `@mget` and `@mput` The macro `@mget` can be used to extract the value of a MATLAB variable into Julia - ```julia julia> mat"a = 6" julia> @mget a @@ -295,7 +293,6 @@ julia> @mget a ``` The macro `@mput` can be used to translate a Julia variable into MATLAB - ```julia julia> x = [1,2,3] julia> @mput x