4 views (last 30 days)

Doing a project with pulse sensor on arduino followed a code online it hit an error im unable to understand im still learning matlab at a basic level can anyone help this is the coding error

Undefined function 'readVoltage' for input arguments of type 'matlab.graphics.axis.Axes'.

Error in mypulsesensor (line 85)

data(i) = readVoltage(a,'A0'); % read voltage on pin A0, store as next data point

Geoff Hayes
on 2 Jan 2020

Muhammad - the problem is with this line of code

a = gca;

where you overwrite the arduino assigned variable with the current axes...and so when you reference a again with

data(1) = readVoltage(a,'A0');

the error occurs because now a is the axes. Consider an alternative name for the axes variable (one that perhaps describes what it references)

hCurrentAxes = gca;

plot(time(i-1:i), data(i-1:i)); %draw the line from the last Vout value to the current Vout value

%actual scroller

%Set appropriate axis limits and settings

set(gcf, 'doublebuffer', 'on');

%Avoiding flickering when updating

set(hCurrentAxes,'xlim',[0 dx]);

set(hCurrentAxes,'ylim',[min(50) - 1, max(200) + 1]); %REMEMBER TO CHANGE X AND Y

%Generate constants for use in UI Control intialization

pos = get(hCurrentAxes, 'position');

or just use gca instead.

You could also rename the variable for the arduino "handle" to something that is more descriptive.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/498697-problem-with-code-for-arduino-voltage-reading#comment_782500

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/498697-problem-with-code-for-arduino-voltage-reading#comment_782500

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/498697-problem-with-code-for-arduino-voltage-reading#comment_782503

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/498697-problem-with-code-for-arduino-voltage-reading#comment_782503

Sign in to comment.