Invalid syntax error when inputting input arguments

I am attempting to get a redboard Arduino Uno to communicate with MATLAB. I have run into the following error when entering input arguments as shown:
function [time, data] = ReadRedBoardData_v2('/dev/cu.wchusbserialfa130', 10, 3000, 'EKG')
Error:Error: File:
ReadRedBoardData_v2.m Line:
1 Column: 45
Invalid expression. Check
for missing multiplication
operator, missing or
unbalanced delimiters, or
other syntax error. To
construct matrices, use
brackets instead of
parentheses.

 채택된 답변

Steven Lord
Steven Lord 2020년 6월 21일
When defining a function you need to give the names of the variables that will contain the data with which the user will call your function.
function [time, data] = ReadRedBoardData_v2(location, x, y, z)
When calling a function you don't include the function keyword.
[time, data] = ReadRedBoardData_v2('/dev/cu.wchusbserialfa130', 10, 3000, 'EKG')
In this call to ReadRedBoardData_v2 (with the definition I gave above) the variable location will contain '/dev/cu.wchusbserialfa130', the variable x will contain 10, the variable y will contain 3000, and the variable z will contain 'EKG'.

댓글 수: 3

Thanks! Now it is telling me that my output arguments appear to be unused. Not sure what that means.
Here is the full code for reference. It looks like the function is being defined and called all in the same script.
If you have a function:
function y = timestwo(x)
q = 2*x;
end
and you call this:
z = timestwo(21)
the value of y inside timestwo will be returned and stored in the variable z. What value is that? Since timestwo never assigned a value to the variable y, MATLAB doesn't know what to return and so you'll receive an error. To fix the problem assign something to the output variable.
function y = timestwo(x)
y = 2*x;
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

질문:

2020년 6월 21일

댓글:

2020년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by