Unexpected MATLAB expression.

조회 수: 1 (최근 30일)
Rebecca Hadley
Rebecca Hadley 2019년 2월 1일
답변: Rebecca Hadley 2019년 2월 5일
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!

채택된 답변

OCDER
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
Rebecca Hadley
Rebecca Hadley 2019년 2월 2일
Hi DL,
Thanks for the help, I still get an error message though. I entered the second example of code you gave and got the following:
>> read_bins
Attempt to execute SCRIPT read_bins as a function:
/Users/becki/Documents/Converting BIN files/CGMR/read_bins.m
Error in read_bins (line 1)
[header, time, xyz, light, button, prop_val] = read_bins('CGMR.bin')
Is it easier for me to show some more of the code? I'm probably being really dense, but as I say, quite new to this.
Thanks again.
OCDER
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개)

Rebecca Hadley
Rebecca Hadley 2019년 2월 5일
Hi DL,
Thank you so much for taking the time to respond! I will do as you suggested and have a look at the difference between script vs function. My challenge for today is to try and resolve this (fingers crossed).

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by