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 日

0 投票

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 件のコメント

Scott hUDSON
Scott hUDSON 2020 年 6 月 21 日
Thanks! Now it is telling me that my output arguments appear to be unused. Not sure what that means.
Scott hUDSON
Scott hUDSON 2020 年 6 月 21 日
Here is the full code for reference. It looks like the function is being defined and called all in the same script.
Steven Lord
Steven Lord 2020 年 6 月 22 日
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 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by