Canvas anomaly in MATLAB regarding GMT

I am using GMT6.6.0dev in MATLAB2023a on Windows 10. I found that the canvas is not correct. For example, I generate a PNG image. The code is as follows.

#Bash code
gmt begin test1 png
gmt coast -R-130/-50/20/60 -JM15c -Bafg -A5000 -W1/0.5p,black
gmt end show
​
%MATLAB code
gmt('begin test2 png');
gmt('coast -R-130/-50/20/60 -JM15c -Bafg -A5000 -W1/0.5p,black');
gmt('end show');
gmt('destroy');

The Bash code runs correctly as shown below.

However, the results of the MATLAB code clearly do not make sense. The manual shows that the default canvas size for GMT is 11.6 meters wide by 11.6 meters high, and that unused white areas are automatically cropped when the final image file is generated, so the user doesn’t need to worry about the size.

So, what is causing the GMT anomaly in MATLAB? How can I fix this problem? Could someone please help me?

Does anyone else have the same problem? Or if anyone else is using GMT in MATLAB without this problem, I’m not sure if it’s a problem with my usage or just the problem itself!

Well, don’t know why the plot is coming out in Landscape but the base issue is probably that the GMT MEX was developed before the modern mode. The fact that it somewhat works in modern mode is a kind of bonus. Probably you’ll have to stick to the classic mode to use the GMT MEX. An alternative, is to try the GMT.jl wrapper that is much more advanced than the Matlab wrapper.

This can be solved with the following code:
system(sprintf(‘gmt psconvert %s/%s.ps -A0.2c -Tj -E600’,psfile,fign));