# MatlabBridge - empty volume by default instead of no volume

**URL:** https://discourse.slicer.org/t/matlabbridge-empty-volume-by-default-instead-of-no-volume/27525
**Category:** Development
**Tags:** matlab
**Created:** [January 29, 2023, 9:04am UTC](https://discourse.slicer.org/t/matlabbridge-empty-volume-by-default-instead-of-no-volume/27525 "2023-01-29T09:04:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![georg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/georg/32/18213_2.png) [@georg](https://discourse.slicer.org/u/georg)
#### Post date: [January 29, 2023, 9:04am UTC](https://discourse.slicer.org/t/matlabbridge-empty-volume-by-default-instead-of-no-volume/27525/1 "2023-01-29T09:04:42Z")

</div>

Dear 3D-Slicer community,

I am developing an extension using MatlabBridge which involves loading 3D and 4D images into 3D-Slicer. I adapted the automatically generated Matlab function to do so, but unfortunately it **only** works when I select “Create new volume” in the dropdown IO \> “Create new volume” (see Figure 2). I have multiple volumes that need to be displayed by 3D-Slicer and I don’t want the user to click through each volume and select “Create new volume”. When I leave the setting at “None” (default, see Figure 1), the code returns the following error:

 ![Bildschirmfoto vom 2023-01-28 23-28-42](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8a1e193b8c5284bf48dd2a96204f811c1a797af6.png)

Is there a way to create an empty volume by default? Maybe by modifying the xml-file or the Matlab function? When using “Create new volume”, the struct “inputParams.outputvolume” contains a path to a nrrd-file and a params-file which are afterwards created by the function “cli\_imagewrite”. I tried to set similar paths (before calling “cli\_imagewrite”) when using the setting “None” for “Output volume”. But this does not work either.

Many thanks in advance for your help.

Figure 1 - not working setting:

 ![Bildschirmfoto vom 2023-01-28 23-01-08](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/9/8911c30506d0bb52166e6729fd4b58311277ae53.png)  
Figure 2 - working setting:  
 ![Bildschirmfoto vom 2023-01-28 23-01-01](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/9/c90bdcd27e137605169c8d827c3e9cf6035c9883.png)

Code:

```auto
function outputParams=test2(inputParams)
outputParams.min=0; % just to prevent no outputParams given error
outputParams.max=0;

load("/home/user/my_mask.mat") % loads the matrix "mask"
img.pixelData=int8(mask);

inputParams.outputvolume.
cli_imagewrite(inputParams.outputvolume, img);

```

---

<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: [January 29, 2023, 9:10am UTC](https://discourse.slicer.org/t/matlabbridge-empty-volume-by-default-instead-of-no-volume/27525/2 "2023-01-29T09:10:11Z")

</div>

By selecting a volume, the user indicates that he is interested in computing that output. Currently, we don’t have an option to automatically create a required output node if the user has not created one. Would you mind creating a feature request in the [Slicer issue tracker](https://issues.slicer.org) to keep track of the ideaI?

---

<div class="post-metadata">

### Author: ![georg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/georg/32/18213_2.png) [@georg](https://discourse.slicer.org/u/georg)
#### Post date: [January 29, 2023, 4:37pm UTC](https://discourse.slicer.org/t/matlabbridge-empty-volume-by-default-instead-of-no-volume/27525/3 "2023-01-29T16:37:55Z")

</div>

Done: [MatlabBridge - option to set output node as default instead of "None" · Issue #6804 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/6804)
