# Matlab Bridge - module execution error - output list of fiducial points

**URL:** <https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407>\
**Category:** Support\
**Created:** [September 12, 2019, 4:33pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407 "2019-09-12T16:33:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlene](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/marlene/32/4566_2.png) [@marlene](https://discourse.slicer.org/u/marlene)\
**Post date:** [September 12, 2019, 4:33pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/1 "2019-09-12T16:33:57Z")

</div>

Operating system:Ubuntu 16.04  
Slicer version: 4.10  
Expected behavior: output fiducial from Matlab Bridge extension  
Actual behavior: error

Hello everybody, I am implementing a Matlab Bridge extension which takes as input:

1. two fiducial markers
2. an input mesh

and as output:

1. a long list of fiducial markers ( which are the 3D coordinates of several paths (up to 10 paths))
2. an output mesh

I get an error on the first output, whenever I try to include even just one single RAS coordinates point as output. Would you help me understanding what I am missing please?

Just to clarify …my final goal would be to plot these paths using CurveMaker so that I am not sure whether there is also a easier way to save trajectories from Matlab and pass them to Slicer.

thank you very much for any suggestion

Marlene

**This is the Matlab Bridge function:**

```auto
function outputParams = New_AFT_slicer(inputParams)

mesh = cli_geometryread(inputParams.inputmesh);
fiducials=cli_pointvectordecode(inputParams.fiducials);

start=fiducials(:,2);
target=fiducials(:,1);

[mesh,path]=sheep_skull_margin(start',target');

outputParams.Paths=path; 
cli_pointfilewrite(inputParams.Paths_calc, path);
cli_geometrywrite(inputParams.outputmesh, mesh);

```

ERROR:

New\_AFT\_slicer standard error:

```auto
Failed to execute Matlab function: New_AFT_slicer, received the following error message: 
ERROR: Command execution failed. Reference to non-existent field 'Paths_calc'.

Error in New_AFT_slicer (line 37)
cli_pointfilewrite(inputParams.Paths_calc, path);

Error in cli_commandserver (line 91)
                response=evalc(cmd);

Error in run (line 91)
evalin('caller', strcat(script, ';'));

```

---

<div class="post-metadata">

**Author:** ![marlene](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/marlene/32/4566_2.png) [@marlene](https://discourse.slicer.org/u/marlene)\
**Post date:** [September 12, 2019, 4:50pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/2 "2019-09-12T16:50:03Z")

</div>

This is the XML:

```auto
<parameters>
    <label>Inputs</label>
    <description><![CDATA[Inputs for the processing]]></description>
    <geometry fileExtensions=".ply" >
      <label>Input model</label>
      <description><![CDATA[Input triangular surface mesh]]></description>
      <longflag>inputmesh</longflag>
      <channel>input</channel>
    </geometry>
    
    
<point multiple="true" coordinateSystem="ras">
      <label>fiducials</label>
      <description><![CDATA[Input volume to be filtered]]></description>
      <longflag>fiducials</longflag>
      <default>0,0,0</default>
      <channel>input</channel>
    </point>

    <label>Output</label>    
    <description><![CDATA[Computed output]]></description>
    <geometry fileExtensions=".ply" >
      <label>Output model</label>
      <description><![CDATA[Transformed triangular surface mesh.]]></description>
      <longflag>outputmesh</longflag>
      <channel>output</channel>
    </geometry>

<point multiple="true" coordinateSystem="ras">
      <label>Paths</label>
      <description><![CDATA[Paths generated]]></description>
      <longflag>Paths_calc</longflag>
      <default>0,0,0</default>
      <channel>output</channel>
    </point>

  </parameters>
</executable>

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 12, 2019, 5:54pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/3 "2019-09-12T17:54:44Z")

</div>

`point` element is uses the command-line to pass point coordinates to the module, therefore cannot be used for output parameter. You have to use `pointfile` element for output point lists instead.

---

<div class="post-metadata">

**Author:** ![roozbehshams](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/roozbehshams/32/1544_2.png) [@roozbehshams](https://discourse.slicer.org/u/roozbehshams)\
**Post date:** [September 13, 2019, 3:12pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/4 "2019-09-13T15:12:25Z")

</div>

Another way is to use Matlab engine for python, which basically gives you access to your current Matlab session in Slicer. I’ve found it to be easier especially when there’s a lot of back and forth between Matlab and Slicer. You can read more here: [https://www.mathworks.com/help/matlab/matlab-engine-for-python.html](https://www.mathworks.com/help/matlab/matlab-engine-for-python.html)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 13, 2019, 3:25pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/5 "2019-09-13T15:25:43Z")

</div>

Thanks for the suggestion. Slicer’s MatlabBridge was developed many years before Matlab’s Python engine was created - maybe we should promote this new integration approach instead.

How do you pass MRML node content between your Matlab functions and Slicer? Using [Python CLI](https://github.com/lassoan/SlicerPythonCLIExample) or by implementing a Python scripted module?

---

<div class="post-metadata">

**Author:** ![roozbehshams](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/roozbehshams/32/1544_2.png) [@roozbehshams](https://discourse.slicer.org/u/roozbehshams)\
**Post date:** [September 13, 2019, 4:15pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/6 "2019-09-13T16:15:49Z")

</div>

By implementing a Python scripted module. From Mathworks: " The `matlab` Python package provides array classes to represent arrays of MATLAB numeric types as Python variables so that MATLAB arrays can be passed between Python and MATLAB.". Like so:

```
import matlab.engine
A = matlab.double([[1,2,3,4,5], [6,7,8,9,10]])
print(A)
[[1.0,2.0,3.0,4.0,5.0],[6.0,7.0,8.0,9.0,10.0]]

```

I haven’t extensively played with passing arrays back and forth since that wasn’t needed in my case, but it looks straight forward. I can put together a simple example if it helps.

---

<div class="post-metadata">

**Author:** ![wpgao](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@wpgao](https://discourse.slicer.org/u/wpgao)\
**Post date:** [December 9, 2020, 6:49am UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/7 "2020-12-09T06:49:33Z")

</div>

Hi Roozbeh,

I had installed Matlab engine for python successfully. However, I can not import it in my module script because the python in Slicer is different from that in the system. So how can use it in my module script?  
Thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 9, 2020, 2:54pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/8 "2020-12-09T14:54:16Z")

</div>

You need to install Python packages in Slicer’s Python environment (e.g., by running `pip_install` command in Slicer’s Python console). You can also use MatlabBridge extension to run Matlab functions from Slicer.

What are those Matlab features that you need that are not available in Python packages?

---

<div class="post-metadata">

**Author:** ![wpgao](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@wpgao](https://discourse.slicer.org/u/wpgao)\
**Post date:** [December 9, 2020, 3:40pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/9 "2020-12-09T15:40:42Z")

</div>

Hi Andras,

Thanks! I followed the instruction ([https://www.mathworks.com/help/matlab/matlab-engine-for-python.html](https://www.mathworks.com/help/matlab/matlab-engine-for-python.html)) mentioned by @roozbehshams, instead, I run "PythonSlicer setup.py install ". It works finally after I upgraded a lib.

There are some powerful Matlab packages in Lead-DBS and SPM which are not available in Python packages, and I plan to add these packages into my module.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 9, 2020, 4:21pm UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/10 "2020-12-09T16:21:48Z")

</div>

> [@wpgao](#):
>
> It works finally after I upgraded a lib.

What exactly you had to upgrade? (just to help others who want to follow this approach)

> [@wpgao](#):
>
> There are some powerful Matlab packages in Lead-DBS and SPM which are not available in Python packages, and I plan to add these packages into my module.

I see. It is very unfortunate that these packages are built on top of closed-source proprietary software. Hopefully they will consider porting their invaluable work to open platforms, until then there is indeed not much else you can do than interface with Matlab.

---

<div class="post-metadata">

**Author:** ![wpgao](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@wpgao](https://discourse.slicer.org/u/wpgao)\
**Post date:** [December 10, 2020, 1:10am UTC](https://discourse.slicer.org/t/matlab-bridge-module-execution-error-output-list-of-fiducial-points/8407/11 "2020-12-10T01:10:56Z")

</div>

The error is “/usr/lib/x86\_64-linux-gnu/libstdc++.so.6: version ‘GLIBCXX\_3.4.22’ not found!

“In my computer there is only GLIBCXX\_3.4.20, so I download libstdc++.so.6.0.22 and install it!
