trying to have two figures on the same screen?

Hi, I am writing a program that displays multiple plots in different figures where the user has to select what figure they want to look at. I am trying to have two of these show up split screen. How would I do this. I provided a snip of the code and the what I want t happen to the plots.show up split screen. How would I do this. I provided a snip of the code and the what I want t happen to the plots.
so Basically I would like these two figures to be displayedin figure 9 half and half

 Accepted Answer

figure(9)
subplot(2,2,[1 3])
%your fig 7 code
subplot(2,2,2)
%fig8 sub1
subplot(2,2,4)
%fig8 sub2

4 Comments

Thank you! I was able to get this to wrok! How come the subplot index change? that is confusing to me. Like for fiugre 8 i had
Subplot(2,1,2) but here it works with subplot(2,2,4)
If you read the subplot documentation you can see the meaning of the first two inputs: the number rows and columns of plots. Your original figure has 2 rows and 1 column, but for the merged figure we want to treat all contents of one figure as a column. This essentially doubles the number of columns.
The third input is the index. Matlab counts column-major, so for 2x2 the indices are [1 3;2 4].
So If i am trying to add 2 more figures do i change this subplot(2,2,[1 3])?
You need to decide how you want to divide your figure space into tiles, then decide how much tiles you want to allocate to each axes.

Sign in to comment.

More Answers (1)

%larger figure on the right
figure;
subplot(2,2,1);
subplot(2,2,3);
subplot(2,2,[2 4]);
%larger figure on the left
figure;
subplot(2,2,2);
subplot(2,2,4);
subplot(2,2,[1 3]);

4 Comments

Why do the indexes change?
A subplot creates axes in tiled positions.
subplot(m,n,p)
%m = number of rows
%n = number of columns
%p = position of current plot
So in your case, whe you create a subplot(2,2,p) - this simply means the subplot has an overall 'matrix' of 2 rows and 2 columns; the 'p' indicates the position of the current plot within this 'matrix' (counting along the top row, then the second row etc).
In short, the indexes change depending on the size of the subplot, and the positioning of the plots.
Hope that makes sense.
So If i am trying to add 2 more figures do i change this subplot(2,2,[1 3])?
Consider this subplot:
figure;
subplot(2,2,1); title('plot 1');
subplot(2,2,2); title('plot 2');
subplot(2,2,3); title('plot 3');
subplot(2,2,4); title('plot 4');
It divides the Figure window into a 2x2 matrix of small axes.
When you concatenate the 1st and 3rd axes the Figure changes accordingly:
figure;
subplot(2,2,[1 3]); title('plot 1');
subplot(2,2,2); title('plot 2');
subplot(2,2,4); title('plot 4');
If you want to add more plots to your subplot, you need to increase the 'm' and/or 'n' value.
subplot(m,n,p)
%m = number of rows
%n = number of columns
%p = position of current plot
For instance, if you want to create a subplot of 6 plots total, you can do this by increasing the number of rows (m) or the number of columns (n).
%increase number of rows
figure;
subplot(3,2,1); title('plot 1');
subplot(3,2,2); title('plot 2');
subplot(3,2,3); title('plot 3');
subplot(3,2,4); title('plot 4');
subplot(3,2,5); title('plot 5');
subplot(3,2,6); title('plot 6');
%increase number of columns
figure;
subplot(2,3,1); title('plot 1');
subplot(2,3,2); title('plot 2');
subplot(2,3,3); title('plot 3');
subplot(2,3,4); title('plot 4');
subplot(2,3,5); title('plot 5');
subplot(2,3,6); title('plot 6');
You can also concatenate the matrix axes to suit your needs; example:
figure;
subplot(2,3,1); title('plot 1');
subplot(2,3,[2 5]); title('plot 2'); %concatentate 2nd and 5th axes
subplot(2,3,[3 6]); title('plot 3'); %concatentate 3rd and 6th axes
subplot(2,3,4); title('plot 4');

Sign in to comment.

Tags

Asked:

on 26 Aug 2020

Commented:

NA
on 26 Aug 2020

Community Treasure Hunt

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

Start Hunting!