MATLAB Answers

## How to continuously real-time plotting graph from arduino to matlab (10k Variable Resistor)

Asked by Charles Lim

### Charles Lim (view profile)

on 13 Aug 2013
Latest activity Answered by Madhu Govindarajan

### Madhu Govindarajan (view profile)

on 17 Oct 2017
Hello and good day to all the experts and visitors of Mat-Lab, I am a mechatronic student and now facing problem trying to interface matlab and arduino..
I am trying to real-time plotting graph from arduino to matlab with (10k variable resistor), but the graph will stop plotting after reach the Maximun X-axis (I set 0-1000).
Can it continuously real-time plotting the graph non stop? full of appreciation or teaching me to solve it.
the code is shown below:
a = arduino('COM3');
interv = 1000;
passo = 1;
t=1;
x=0;
while(t<interv)
b=a.analogRead(0);
x=[x,b];
plot(x);
axis([0,interv,0,1024]);
grid
t=t+passo;
drawnow;
end

Kerone Naidoo

### Kerone Naidoo (view profile)

on 8 Mar 2017
Hi,
just dont bound the axis, remove the bounds on the axis and that should allow it to continually plot the voltage.

Sign in to comment.

## 6 Answers

### David Sanchez (view profile)

Answer by David Sanchez

### David Sanchez (view profile)

on 13 Aug 2013

You just have to change the axis when the highest value is reached:
axis([interv,2*interv,0,1024]); % adapt values to your needs

Charles Lim

### Charles Lim (view profile)

on 16 Aug 2013
Very Thank you for replied
I set interv = 1000
after I change this code
the x-axis started from 1000 to 2000
how do I start from 0 - 1000 after the highest value is reached auto start from 1000 - 2000 , continuously non stop ?

Sign in to comment.

Answer by anand

### anand (view profile)

on 22 Dec 2016

just make use of while(1) after a = arduino and at the last make use of a end function this solves your problem

#### 0 Comments

Sign in to comment.

### Sanjay Raam (view profile)

Answer by Sanjay Raam

### Sanjay Raam (view profile)

on 9 Feb 2014
Edited by Sanjay Raam

### Sanjay Raam (view profile)

on 9 Feb 2014

you need not set axis between 0to1024
instead give the following statement
axes auto;
by the way, thanks for your program... it was useful for me to learn!!

#### 0 Comments

Sign in to comment.

### khoulod ghanem (view profile)

Answer by khoulod ghanem

### khoulod ghanem (view profile)

on 28 Sep 2015

I am trying to plot current-voltage curve from Arduino to Matlab , can you help me to start ??

#### 0 Comments

Sign in to comment.

### ravi kumar (view profile)

Answer by ravi kumar

### ravi kumar (view profile)

on 2 Feb 2017

This did not work for me. I tried this one: Real Time Analog Voltage in Matlab using Arduino it uses line function. anybody knows how to scroll the time line?

prasad noolu

### prasad noolu (view profile)

on 17 Aug 2017
try this code: clear all
a = arduino
x = 0;
for k = 1:1000
b = readVoltage(a, 'A0');
x = [x, b];
plot (x);
grid;
drawnow;
end

Sign in to comment.

### Madhu Govindarajan (view profile)

Answer by Madhu Govindarajan

### Madhu Govindarajan (view profile)

on 17 Oct 2017

Checkout this video - https://www.mathworks.com/videos/plotting-live-data-of-a-temperature-sensor-using-arduino-and-matlab-121317.html?s_tid=srchtitle
HTH, Madhu

#### 0 Comments

Sign in to comment.