# Developers Planet

KeepLearning February 2016

### Plot in uitabgroup (matlab GUI)

Suppose I have 3 functions

1. f(x)=2x+4
2. h(x)=2x+5
3. g(x)=2x+6

I have 3 uitabs which belong to each function.

When user input the x data,

``````  e.g X=[1;2;3;4]
``````

for each uitab, I want to see something like this:

1st uitab:

``````plot (X,2.*X+4);
``````

2nd uitab:

``````plot (X,2.*X+5);
``````

3rd uitab:

``````plot (X,2.*X+6);
``````

My question:

1. How to plot the graph simultaneously to each uitab?

2. And how to make sure that when user change the input, the new graph will be shown and not overlap with the old one?

Thanks!!

Suever February 2016

For each tab, you will want to explicitly create an `axes` and then specify this as the parent of the plot.

``````group = uitabgroup();

tab1 = uitab(group, 'Title', 'Tab1');
tab2 = uitab(group, 'Title', 'Tab2');
tab3 = uitab(group, 'Title', 'Tab3');

hax1 = axes('Parent', tab1);
hax2 = axes('Parent', tab2);
hax3 = axes('Parent', tab3);

plot1 = plot(X, 2.*X + 4, 'Parent', hax1);
plot2 = plot(X, 2.*X + 5, 'Parent', hax2);
plot3 = plot(X, 2.*X + 6, 'Parent', hax3);
``````

Then when you alter the value of X you can explicitly update these plots

``````set(plot1, 'XData', X, 'YData', 2.*X + 4);
set(plot2, 'XData', X, 'YData', 2.*X + 5);
set(plot3, 'XData', X, 'YData', 2.*X + 6);
``````