Unexpected MATLAB expression.

2 Ansichten (letzte 30 Tage)
Rebecca Hadley
Rebecca Hadley am 1 Feb. 2019
Beantwortet: Rebecca Hadley am 5 Feb. 2019
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!

Akzeptierte Antwort

OCDER
OCDER am 1 Feb. 2019
Bearbeitet: OCDER am 1 Feb. 2019
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 Kommentare
Rebecca Hadley
Rebecca Hadley am 2 Feb. 2019
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 am 2 Feb. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rebecca Hadley
Rebecca Hadley am 5 Feb. 2019
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).

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by