# Colorbar module error in GMT within MATLAB

**URL:** <https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [March 10, 2024, 7:24am UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709 "2024-03-10T07:24:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ximoge](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ximoge/32/4026_2.png) [@ximoge](https://forum.generic-mapping-tools.org/u/ximoge)\
**Post date:** [March 10, 2024, 7:24am UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709/1 "2024-03-10T07:24:03Z")

</div>

I am using GMT6.6.0dev within MATLAB2023a on Windows10. So far, everything is fine except the colorbar module. For example,

My Bash code is ok,

```auto
gmt begin test png
 	gmt grdimage @earth_relief_01m -JM15c -R118/125/20/26 -Baf -BWSen -I+d
	gmt colorbar -DJMR+w10c+o1.5c/0c+ml -Bxa1000f -By+l"m"
gmt end show

```

my MATLAB code is wrong,

```auto
gmt('begin test png')
	gmt('grdimage @earth_relief_01m -JM15c -R118/125/20/26 -Baf -BWSen -I+d');
	gmt('colorbar -DJMR+w10c+o1.5c/0c+ml -Bxa1000f -By+l"m"');
gmt('end show');
gmt('destroy');

```

Error message,

```auto
错误使用 gmtmex
GMT: Attempting to address a prhs entry that does not exist

出错 gmt (第 33 行)
		[varargout{1:nargout}] = gmtmex (cmd, varargin{:});

出错 gmt_test (第 3 行)
gmt('colorbar -DJMR+w10c+o1.5c/0c+ml -Bxa1000f -By+l"m"');

```

Could anyone help me?

---

<div class="post-metadata">

**Author:** ![ximoge](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ximoge/32/4026_2.png) [@ximoge](https://forum.generic-mapping-tools.org/u/ximoge)\
**Post date:** [March 10, 2024, 2:43pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709/2 "2024-03-10T14:43:01Z")

</div>

One possible reason is that when using GMT in Matlab, grdimage can read the hidden current cpt, but colorbar cannot. This means that colorbar needs an input parameter - cpt.

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [March 11, 2024, 11:56am UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709/3 "2024-03-11T11:56:49Z")

</div>

In bash, `colorbar` finds the hidden `cpt`. You could add any cpt in the `colorbar` command to see if this is the problem.

---

<div class="post-metadata">

**Author:** ![ximoge](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ximoge/32/4026_2.png) [@ximoge](https://forum.generic-mapping-tools.org/u/ximoge)\
**Post date:** [March 11, 2024, 12:12pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709/4 "2024-03-11T12:12:46Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [March 11, 2024, 1:04pm UTC](https://forum.generic-mapping-tools.org/t/colorbar-module-error-in-gmt-within-matlab/4709/5 "2024-03-11T13:04:07Z")

</div>

Very likely the same reason as in the other post. The MEX parser probably does not know that an automatic CPT has been created ans is expecting it to be passed as argument in the `gmt('colorbar ...` command.
