Filter löschen
Filter löschen

subplotのfi​gureからCSVデ​ータを取り出す方法

58 Ansichten (letzte 30 Tage)
Osamu Goto
Osamu Goto am 18 Apr. 2024
Kommentiert: Osamu Goto am 19 Apr. 2024
Matlab R2020aの環境下で、.figファイルを読み込んで、figureを読み込んでいます。
そのfigureには、例えば、subplotで2x2の描画画面があり、その1画面の中に複数plotがある場合、
それぞれ描画されている元のデータをCSVで引き出す方法はあるでしょうか?
元データは無くしてしまい、.figデータだけ手元にあるので、よろしくお願いします。

Antworten (1)

Atsushi Ueno
Atsushi Ueno am 18 Apr. 2024
figureハンドル.Children(m).Children(n).X(Y)Data で目的のXY軸情報にアクセスできます。
データの取り出し方は示せてるかと思いますが、行列に突っ込んでいくなどいいかげんです。
なので、より詳細な方法について要求があればコメントください。
%% サンプルデータを作成する
fig = figure; x = linspace(0,10)';
subplot(2,2,1); y1 = [sin(1*x) cos(1*x)]; plot(x,y1); title('Subplot 1: sin(1x), cos(1x)');
subplot(2,2,2); y2 = [sin(2*x) cos(2*x)]; plot(x,y2); title('Subplot 2: sin(2x), cos(2x)');
subplot(2,2,3); y3 = [sin(4*x) cos(4*x)]; plot(x,y3); title('Subplot 3: sin(4x), con(4x)');
subplot(2,2,4); y4 = [sin(8*x) cos(8*x)]; plot(x,y4); title('Subplot 4: sin(8x), cos(8x)');
saveas(fig,'figure1'); % fig ファイル figure1.fig を作成
close(fig); % fig ファイルに保存した figure をクローズする
%% fig ファイルからデータを読み込み CSV 化する
dat = [];
hfig = openfig('figure1.fig','invisible'); % figure は表示しない
for chld = hfig.Children' % 全てのサブプロットを走査
for axs = chld.Children' % 全ての XY 軸データを走査
dat = [dat; axs.XData; axs.YData]; % 行列に収めていく
end
end
writematrix(dat, 'test.csv'); % 順番が逆になっちゃった。ご愛敬
  1 Kommentar
Osamu Goto
Osamu Goto am 19 Apr. 2024
ありがとございました。

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu グラフィックス オブジェクトのプログラミング finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!