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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by