Skip to content

Commit b5e0e87

Browse files
committed
doku final rst
1 parent e260366 commit b5e0e87

File tree

3 files changed

+66
-85
lines changed

3 files changed

+66
-85
lines changed

docs/_pages/2_guideExamples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _examples::
22

33
*******************************
4-
Guide - Examples and How to Use
4+
Example Codes
55
*******************************
66

77
It is the aim of this section to give a few code examples that show how the library can be used. Detailed information about the library structure can be found in the :ref:`docu`.
@@ -113,7 +113,7 @@ The superposition principle allows us to calculate complex magnet shapes by 'add
113113
Vectorized vs Classical Code
114114
######################################
115115

116-
Description coming up tomorrow :)
116+
In this example a magnet is tilted above a sensor just like in a 1D-joystick system. The magnetic field is computed using vectorized code, taking care to create the ``getBv`` input using numpy native methods only.
117117

118118
.. plot:: pyplots/examples/05_VectorJoystick1d.py
119119
:include-source:

docs/_pages/3_MATLAB.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

docs/_pages/3_MATLAB.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.. _matlab:
2+
3+
******************
4+
MATLAB Integration
5+
******************
6+
7+
.. note::
8+
9+
MATLAB does not support Tkinter, which disables matplotlib. This means that :meth:`~magpylib.Collection.displaySystem()` will not generate a display and might interrupt the program.
10+
11+
12+
Setting Python Interpreter
13+
###########################
14+
15+
As of version R2015b, MATLAB allows you to call libraries from other programming languages, including Python, which enables users to run magpylib from the MATLAB interface. The following guide intends to provide a digest of the `Official MATLAB documentation <https://www.mathworks.com/help/matlab/call-python-libraries.html>`_ with a focus on utilizing this interface with magpylib.
16+
17+
Running ``>>> pyversion`` following line in the MATLAB console tells you which Python environment (user space interpreter) is connected to your MATLAB interface.
18+
19+
If magpylib is already installed in this environment you can directly call it, as shown in the `Example`_ below. If not please follow the :ref:`installation` instructions and install magpylib.
20+
21+
If you choose to install magpylib in a different environment than the one that is currently connected to your MATLAB interpreter, use the following command in the MATLAB console to connect the new environment instead (choose correct path pointing at your Python interpreter).
22+
23+
.. code-block:: matlab
24+
25+
>>> pyversion C:\Users\...\AppData\Local\Continuum\anaconda3\envs\magpy\python.exe
26+
27+
28+
Example
29+
############
30+
31+
The following MATLAB 2019 script showcases most functionalities.
32+
33+
.. code-block:: matlab
34+
35+
%%%%%%%%%%%%%%%%%% magpytest.m %%%%%%%%%%%%%%
36+
%% Showcase Python + MATLAB Interoperability.
37+
%% Define and calculate the field of a
38+
%% Cuboid magnet inside a Collection.
39+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40+
41+
%% Import the library
42+
py.importlib.import_module("magpylib")
43+
44+
%% Define Python types for input
45+
vec3 = py.list({1,2,3})
46+
scalar = py.int(90)
47+
48+
%% Define input
49+
mag = vec3
50+
dim = vec3
51+
angle = scalar
52+
sensorPos = vec3
53+
54+
%% Execute Python
55+
% 2 positional and 1 keyword argument in Box
56+
box = py.magpylib.source.magnet.Box(mag,dim,pyargs('angle',angle))
57+
col = py.magpylib.Collection(box)
58+
pythonResult = col.getB(sensorPos)
59+
60+
%% Convert Python Result to MATLAB data format
61+
matlabResult = double(pythonResult)
62+
63+
.. note::
64+
With old versions of Matlab the *double(pythonResult)* type conversion might give an error message.

0 commit comments

Comments
 (0)