Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Using Slider on a Plot

Subject: Using Slider on a Plot

From: Nuri

Date: 3 Apr, 2010 09:24:05

Message: 1 of 3

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

Subject: Using Slider on a Plot

From: Nuri

Date: 3 Apr, 2010 11:08:04

Message: 2 of 3

any help?

Subject: Using Slider on a Plot

From: Sadik

Date: 3 Apr, 2010 15:17:23

Message: 3 of 3

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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us