Unexpected MATLAB expression.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I'm a MATLAB newbie and am really struggling with some code that has been given to me by a software company for importing BIN files containing acceleration data.
Can anyone help me with what the error means?
function [header, time, xyz, light, button, prop_val] = read_bin('CGGM.bin', varargin)
There is more to the code than the above, but the error seems to point to an issue with this line. Thanks in advance!
댓글 수: 0
채택된 답변
OCDER
2019년 2월 1일
편집: OCDER
2019년 2월 1일
function [header, time, xyz, light, button, prop_val] = read_bin('CGGM.bin', varargin)
^^^^^^^^^
You can't have a string as an input "parameter" name.
function [header, time, xyz, light, button, prop_val] = read_bin(Input1, varargin)
To input "CGGM.bin" as an input to your function, do this
>> [header, time, xyz, light, button, prop_val] = read_bin('CGGM.bin', ...)
댓글 수: 2
OCDER
2019년 2월 2일
You have a recursive summon, as in your script (read_bins) is trying to summon itself (read_bins). Make sure a script name is different from a function name. Look up the difference between script vs function for Matlab on the search engine
Example of a script called addScript.m
In1 = 2;
In2 = 3;
A = In1 + In2; %Note, there is no use of the word "function" in the code.
Example of a function called addFunc.m
function Out = addFunc(In1, In2)
A = In1 + In2; %Note, this is a "function" that accepts inputs "In1" and "In2".
To use a function, do this:
>> A = addFunc(2, 3)
To use a script, do as you did:
>> addScript
Overall, I'd stay away from using scripts, as it's used often as a temporary code for setting up equations, parameters, etc., before wrapping the code into a function.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!