Combining multiple existing plots
55 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have generated multiple MATLAB figures using a code that I have to manually edit each time. Just wondering if there is a way I can combine these pre-existing figures into one figure that shows the data overlapped from each figure.
0 件のコメント
回答 (1 件)
Voss
2022 年 3 月 13 日
編集済み: Voss
2022 年 3 月 13 日
You can try doing something like what follows. This assumes each figure has one axes and you want to put all graphics objects from every figure's axes into a single axes in a new figure. Axes properties such as labels and titles - as well as any legends - will not be preserved, but see if this is at least a step in the right direction. (If the figures you have are saved as .fig files you can use the same approach - just open() each one and subsequently delete() it inside the for loop.)
% first, I create a couple of figures containing some lines
fig_1 = figure();
plot(1:10);
fig_2 = figure();
plot(2:11);
drawnow();
% now combine the figures' contents into a new figure
% specify which "old" figures to use
figs = [fig_1 fig_2];
% make a "new" figure
f = figure();
% get the new figure's axes
ax = gca();
% for each old figure
for ii = 1:numel(figs)
% find all the graphics objects in the figure's axes
obj = findall(get(figs(ii),'CurrentAxes'));
% remove the axes itself
obj(strcmp(get(obj,'Type'),'axes')) = [];
% copy the objects to the new figure's axes
copyobj(obj,ax);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


