Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-21 17:03:14 +01:00 committed by GitHub
parent f7c2314691
commit 833fb28487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,6 +126,9 @@ import matlab.engine
eng = matlab.engine.start_matlab() eng = matlab.engine.start_matlab()
``` ```
If now error message pops up then you should be ready to go!
## First test ## First test
```python ```python
@ -174,8 +177,16 @@ PS C:\Users\admin\Documents\MATLAB> python.exe .\matlab1.py
Press enter to continue Press enter to continue
If you use VS Code in cell mode, you will get a cold stare instead of the text output. ![image1](2023-12-21_16-56.png)
If you use VS Code in cell mode, you will get a cold stare instead of the text output. You need to add
```python
# %%
%matplotlib widget
```
to your python code.
## Getting data from the Matlab workspace ## Getting data from the Matlab workspace
@ -189,7 +200,7 @@ eng = matlab.engine.start_matlab()
eng.eval("clear all", nargout=0) eng.eval("clear all", nargout=0)
eng.eval("a = rand(100,10);", nargout=0) eng.eval("a = rand(100,10);", nargout=0)
data_mat = eng.workspace["a"] data_mat = eng.workspace["a"]
print(type(data_mat)) # --> import numpy as np print(type(data_mat)) # --> <class 'matlab.double'>
a = np.array(data_mat) a = np.array(data_mat)
print(type(a)) # --> <class 'numpy.ndarray'> print(type(a)) # --> <class 'numpy.ndarray'>
print(a.shape) # --> (100, 10) print(a.shape) # --> (100, 10)
@ -203,17 +214,18 @@ import matlab.engine
eng = matlab.engine.start_matlab() eng = matlab.engine.start_matlab()
Output = eng.eval("A = 1", nargout=1) # Error!!!
eng.eval("A = 1;", nargout=0) eng.eval("A = 1;", nargout=0)
Output = eng.eval("A", nargout=1) Output = eng.eval("A", nargout=1)
print(Output) # --> 1.0 print(Output) # --> 1.0
Output = eng.eval(
"A = 1", nargout=1
) # SyntaxError: Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
``` ```
## Exchanging data with Matlab bi-directionally ## Exchanging data with Matlab bi-directionally
```python ```python
# %%
import matlab.engine import matlab.engine
import matlab import matlab
import numpy as np import numpy as np