1

I am trying to create a smaller plot within a plot in MATLAB, for example like the image of this MATLAB File Exchange Upload. There, two figures are created and then both of them are plotted in one figure.

My problem however is that I already have two MATLAB figures from earlier simulations and I need to embed one figure into the other one, i.e., one would be small and the other plot would be big but in the same graph. Could someone suggest an easy way to do this?

2
  • How do you have the existing MATLAB figures? As *.fig files? Commented Jul 6, 2015 at 12:54
  • Yes, both of them are *.fig files Commented Jul 6, 2015 at 12:55

1 Answer 1

5

This can be done using the copyobj function. You'll need to copy the Axes object from one figure to the other:

f(1) = openfig('fig1.fig');
f(2) = openfig('fig2.fig');

ax(1) = get(f(1),'CurrentAxes');                % Save first axes handle
ax(2) = copyobj(get(f(2),'CurrentAxes'),f(1));  % Copy axes and save handle

Then you can move and resize both axes as you like, e.g.

set(ax(2),'Position', [0.6, 0.6, 0.2, 0.2]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.