Skip to content

Commit 25a047b

Browse files
authored
Add a example for Calling custom MATLAB function (#202)
* Add a example for Calling custom MATLAB function * Update README.md * Update README.md
1 parent d9a79c0 commit 25a047b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,38 @@ julia> @show y
310310
a = 63.0
311311
```
312312

313+
#### Calling custom MATLAB function
314+
315+
If the MATLAB function is not in the current directory, we need to first add it to the MATLAB path before calling through Julia:
316+
317+
```julia
318+
mat"addpath('/path/to/folder')"
319+
val = mat"myfunction($arg1, $arg2)"
320+
```
321+
For example, if there is a MATLAB file located at `/path/to/folder` with contents:
322+
323+
```matlab
324+
function [r,u] = test(x, y)
325+
r = x + y;
326+
u = x - y;
327+
end
328+
```
329+
330+
We can call this function as follows in Julia:
331+
332+
```julia
333+
using MATLAB
334+
335+
x = range(-10.0, stop=10.0, length=500)
336+
y = range(2.0, stop=3.0, length=500)
337+
338+
mat"addpath('/path/to/folder')"
339+
340+
r, u = mxcall(:test,2,x,y)
341+
```
342+
343+
344+
313345
#### Viewing the MATLAB Session (Windows only)
314346

315347
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.*

0 commit comments

Comments
 (0)