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.

 采纳的回答

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 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by