3

Matlab の Mapping Toolbox を使用して、北アメリカの円錐投影図を作成および印刷しています。IDE 内でコードを実行すると、プロットは正しく印刷されて保存されますが、コマンド ラインで -nodisplay -nodesktop -nosplash を使用して同じスクリプトを実行すると、非常に奇妙な問題が発生します。

print() 関数の呼び出し中に、Matlab はエラー、警告、またはクラッシュ ログなしでスクリプトの実行を停止します。Matlab は実際にはクラッシュしません...コードの実行が停止するだけです。これによると、表示なしで図を印刷することが可能になると思われます。

他の人が同様の問題に遭遇し、MathWorks Web サイトで質問しています。

この問題を再現するコードを次に示します。

これまでのところ、誰も解決策を思い付いていません。誰か提案はありますか?前もって感謝します!

編集1:

問題を再現するための自己完結型のコードを次に示します。R2011b と R2012a の両方でテストしました。

figure(1)
axesm eckert4; framem; gridm; axis off; tightmap

load geoid
contourfm(geoid, geoidrefvec, -120:20:100, 'LineStyle', 'none');

coast = load('coast');
geoshow(coast.lat, coast.long, 'Color', 'black')

contourcbar

print('-f1','-dpng','-r200','-painters', 'example');
4

2 に答える 2

2

たとえば、次のようなスクリプトを使用して MATLAB を実行すると、次の警告が表示されます。

#!/bin/sh
nohup matlab -nodisplay -nodesktop -r myCode > myLog.log &
exit  

.

[Warning: Objects of graph2d.lineseries class exist - not clearing this class or
any of its superclasses] 
[Warning: Objects of scribe.legend class exist - not clearing this class or any
of its superclasses] 
[Warning: Objects of graphics.panbehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.zoombehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.rotate3dbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.datacursorbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.ploteditbehavior class exist - not clearing this
class or any of its superclasses]

問題は、matlab コードが Figure やプロットなどを表示したいのに、オプションがそれを-nodisplay禁止していることです。この問題を解決するには、次の行をコードに追加set(gcf, 'visible','off');し、最後にclose gcf; clear gcf;. これで、プロットの凡例はシフトなしの最初のプロットと同じになり、警告も表示されませんでした。

于 2013-11-07T22:15:44.747 に答える
1

この問題は解決できず、バグであるという結論に達しました。

問題の解決に最も近いのは、シェルから次のコードを使用することです。

$ matlab -nosplash -nodisplay < makefigure.m

makefigure.m:

plot(randn(100,1)); 
set(gca,'Units','normalized','Position',[0.13 0.11 0.775 0.815]);
set(gcf,'Units','pixels','Position',[4 4 1200 900]);  %# Modify figure size
hgexport(gcf,'myfig.png',...
    hgexport('factorystyle'),'Format','png');

これにより、1200x900 ピクセルの png ファイル「myfig.png」が出力されます。残念ながら、画像は希望のサイズですが、グラフ自体はまだ小さいサイズです。これの原因は確かではありませんが、Matlab がオブジェクト指向であり、軸が Figure のサイズにリンクされているという事実と関係があると思います(これが gca の 'Position' 変数です)。に正規化されます)。なんらかの理由で、これは特にディスプレイがオフになっている場合には発生しません。これが Mathwoks によってすぐに解決されるとは思えません。また、Matlab ユーザーの大多数が GUI を使用しているため、Mathwoks を責めることはできません。

これを修正する手段を持っている人を助ける可能性のある 1 つの手がかりは、コマンド ラインで実行するとエラーが発生することです。

Warning: Objects of graph2d.lineseries class exist - not clearing this class
or any of its super-classes 

解決策を探しましたが、さらに質問が見つかりました。私の疑いでは、誰かがそれが何を意味するのかを理解できれば、この問題を解決できると思います. 今のところ、もう一度 Python に戻ります。なぜなら、Matlab を使用すると、生産的ではなく、不都合に対処するのに何時間も費やすだけだからです。

編集:役立つ場合、これはLinux上のMatlab 2012aで​​す... 2.6.35.6-45.fc14.x86_64 #1 SMP ... x86_64 x86_64 x86_64 GNU/Linux

于 2012-10-04T16:39:15.780 に答える