Using Slider on a Plot

  • Follow


Hi,

I asked this before and searched a lot of times but i couldn't find a solution.

My want to plot 3 graphs and change one of them's value with a slider. But each time I use the slider to change the value, it plots another graph and keeps the old ones (like this: http://i40.tinypic.com/2uelhcl.jpg). 

Here is my files: http://duckload.com/download/465993/untitled.rar  

I will be very happy if anyone can fix it or give me an example file. Thanks for your help.

Regards
0
Reply Nuri 4/3/2010 9:24:05 AM

any help?
0
Reply Nuri 4/3/2010 11:08:04 AM


Hi Nuri,

What you should do is find the handle of the green line you would like to move.

The way to do it is the following:

1. When you plot the green line the first time, in your slider1_CreateFcn, keep its handle by 

lineHandle = plot(... % your green line plot.

2. Then carry this on to your other callbacks by putting it into the handles structure:

handles.greenLine = lineHandle;
guidata(hObject, handles);

3. Now, in slider1_Callback, retrieve this handle:

lineHandle = handles.greenLine;

4. Once you do that, you can now modify the xData and yData properties of your line using the variable lineHandle. Something like:

% new values according to slider value
newXData = ...
newYData = ... 
set(lineHandle,'xData',newXData,'yData',newYData);

This way, you are updating the data of your line, rather than making a new line.

Best.
0
Reply Sadik 4/3/2010 3:17:23 PM

2 Replies
637 Views

(page loaded in 0.051 seconds)

Similiar Articles:













7/24/2012 1:07:12 AM


Reply: