Thursday, February 23, 2012

GUI in MATLAB 4

Today we're making plots.
To make plots we need x and y data.
We're making 2 plots, so here we go.

Then, open a blank window using "figure", and put 2 axes on it.
If you're not familiar with "axes" this may look a bit odd. You may think "wait. I thought it was axis, not axes".
Well, they are different. You can think of it this way.
The figure you just opened is like a wall. Then you put a white piece of paper so you can draw things on it. This white piece of paper is "axes" The "axes" has x and y "axis".

Another thing to notice is "Parent" and "units". I'm not very good with other programming languages, so I don't know if others have this concept, but this is what people call "Parent" in MATLAB.
I mentioned that "axes" is like a piece of paper, right? This paper should have a wall to go to. "Parent" tells MATLAB which wall to put it to. This is quite useful when you have more than one of something to work with simultaneously.

If you have 2 figures opened up, you want to put your axes on a correct figure. We'll see this again when we put plots on the axes.

I set units to be pixel. This is something I didn't specified in the earlier posting when I was playing with figure. For some reason (unfortunately I don't know why this is default) the default setting for axes position is normalized value - going from 0 to 1. So you need to change the setting to put your axes on a precise location on the figure.

Now, let's put plots on the axes we just made. We're making 2 plots and each axes will take one.
Try the following.
 
Here I used axes handle, A1 and A2, as parents to direct which plot goes where.

This is the final result.
Ha! That was easy.

Now try this.

Now your blue line is thicker.

If you're wondering what else you can change, you can always try "get(P1)" or "set(P1)".

Next time I'll show you how to make buttons for different types of controls.



No comments:

Post a Comment