Input argument 'x' is undefined

I have written this function in the script M-File,
function getData(board)
data = fread(board, 10)
fread(board,board.BytesAvailable);
figure(1);Stripchart(data(1:end));
but when i try running this, it shows me this error,
Error in ==> stripfunc at 2
data = fread(board, 10)
I have named the 'file stripfunc'.
Please help me out here,I'm kinda new to programming. Thanks in advance.

Answers (1)

Nishant - from your question it seems that you have a function called getData in a file called stripfunc.m. Is the function definition and body the only contents of this file? If so, then your file should hand the same name as the function, or the function should have the same name as the file.
Consider renaming the function to
function stripfunc(board)
and then see what happens when you call this function. Ensure that when you call stripfunc that you are passing the board input parameter.
If your file has more than just this function defined within it, then please post more of your code so that we can see how you are calling the getData function from within the script.

5 Comments

Hey Geoff,thanks for replying.I tried doing what you suggested,but its showing a similar error.I'm trying to read the data from an usb port to which an arduino is attached.The data is received by the usb because i can see the changes in the serial monitor of the arduino ide.
This is what i'm trying to do.I've followed every step precisely,but its the error that's causing me a problem.
Nishant- please post more of your code and the full error message so that we can get an idea as to which line is throwing the error.
%%create a serial object
board = serial('COM4','BaudRate',9600,'DataBits',8)
fopen = (board);
%%initialise the strip chart
clf
Fs = 300;
AxesWidth = 2;
figure(1); stripchart(Fs,AxesWidth);
%%%%timer function
t = timer('TimerFcn',@(x,y)getData(board),'Period',0.1);
set(t,'ExecutionMode','fixedRate');
start(t);
This is the code typed in a different m-file.I've followed the steps according to the pdf file in the link.Then,according to the pdf,i have to type this code,
function stripfunc(board)
data = stripfunc(board, 10);
fread(board,board.BytesAvailable);
figure(1);Stripchart(data(1:end));
in another m-file.Then I tried executing the program.Then it displays this message,
??? Input argument "board" is undefined.
Error in ==> stripfunc at 2
data = stripfunc(board, 10);
P.S:the line 'function stripfunc(board)' was changed from 'function getdata(board)' as you said in the previous comment.
The error might be silly,but I still don't get it.
Nishant - I'm not sure if it is a typo when copying your code to the above, but the line
fopen = (board);
should instead be
fopen(board)
as you are opening the serial object. And since the timer callback is initialized as getData in the line
t = timer('TimerFcn',@(x,y)getData(board),'Period',0.1);
then your callback function must be in a file called getdata.m with the function name the same as the file name. So the contents of this file would be
function getData(board)
data = stripfunc(board, 10);
fread(board,board.BytesAvailable);
figure(1);Stripchart(data(1:end));
I glanced at the pdf, and feel that you should have two files - the callback function getData.m and the script which has all the code (less the callback) that you have pasted above. You would then call the script from the command line.
Also, why do you call stripfunc from within the function stripfunc? This is incorrect and is very different from what you have pasted way up in your question.
As for the error message, it is telling you that the board input is undefined, almost as if you have called the function without supplying an input.
So please do the following - attach your script and callback to the question so that I can get an idea of what code you are running, and write how you are executing this code. i.e. how are you calling this function from the command line?
Nishant's "Answer" moved here because it is not an answer to the originally posted question but actually a comment to Geoff:
Hey Geoff,I tried the whole thing again,but its showing the same error. Anyway,I found another way of connecting the arduino board to matlab. Thanks for your help.

Sign in to comment.

Asked:

on 10 Jan 2015

Commented:

on 25 Jan 2015

Community Treasure Hunt

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

Start Hunting!