Unable to plot graph on matlab using arduino

Hi all, I am new to Arduino so please help me on this. For my school project, I am required to log data produced by my Arduino using matlab on realtime. Here is my code for Matlab: By using this code I am supposed to get 4 outputs on my Arduino that I can use to plot my values to time graph using matlab. Hence I have written a code for matlab (for 2 of the sensors as an initial test):
clear all
a = arduino ;
line1 = line(nan, nan, 'color', 'red');
line2 = line(nan, nan, 'color', 'blue');
i = 0;
while 1
sensor1 = readDigitalPin(a, 'D3');
sensor2 = readDigitalPin(a, 'D6');
pause(0.5);
x1= get(line1, 'xData');
y1= get(line1, 'yData');
x2= get(line2, 'xData');
y2= get(line2, 'yData');
x1=[x1 i];
y1=[y1 sensor1];
x2=[x2 i];
y2=[y2 sensor2];
set(line1, 'xData', x1, 'yData', y1);
set(line2, 'xData', x2, 'yData', y2);
i=i+1;
pause(1)
end
However with that I am unable to get an output graph at all and I am unable to understand why. Is there any problems with my above code?

Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Asked:

on 4 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!