Input argument 'x' is undefined
Show older comments
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)
Geoff Hayes
on 10 Jan 2015
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
Nishant
on 12 Jan 2015
Geoff Hayes
on 12 Jan 2015
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.
Nishant
on 12 Jan 2015
Edited: Geoff Hayes
on 13 Jan 2015
Geoff Hayes
on 13 Jan 2015
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?
Image Analyst
on 25 Jan 2015
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.
Categories
Find more on Clocks and Timers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!