Brace indexing not supported for variable of this type error - matlab

I am running a display code for Matlab network expansion problem.
This problem Variables are initialized as:
Coll=null(1);v=null(1);
The section with the error:
nco=size(Coll,1);
oc = Coll {nco,1};
oc line gives the brace indexing error.
I tried changing braces to parentheses,the error changed to index in position 2exceeds array bound.
Coll is a 1×0 double while nco is a 1×1 double on my workspace.
I also tried with
oc = [Coll{nco,1}];
This terminates the problem but does not a sign to display.

Related

For MATLAB mirfeatures function I get the valid interpreter syntax error

Following this manual page 195, I run the f = mirfeatures(a), where a is a miraudio('mysong.wav') object. Then I want to get the results stored in f. However, I get the following error after this command: f.dynamics.rms{1}
Brace indexing is not supported for variables of this type.
and the following warning after this command: f.dynamics.rms
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
RMS energy, E:\Video-Project\Watches\audio_320k_44100_1122002.wav
> In defaulterrorcallback (line 12)
In mirscalar/display_figure (line 390)
In mirscalar/display (line 10)
I need to mention that when I run mirrms(a). I get no warning. The mentioned commands are on the manual page 195.
Also. f.dynamics.rms generates a figure.
Here is the code and the audio file:
a = miraudio('audio_320k_44100_1122002.wav');
f = mirfeatures(a);
f.dynamics.rms;
f.dynamics.rms{1};

Ocaml error unbound Value

When i try to evaluate line 2 or 5 of this program, i get "Unbound value carre" or "Unbound value bis".
To evaluate it i use emacs with tuareg, could it be related ?
let carre x = x*x;;
carre(9);;
let bis y = y^y;;
bis("ab");;
For example, here is what i get for line 2 :
# Characters 0-5:
carre(9);;
^^^^^
Error: Unbound value carre
#
The code is very simple so i feel like the problem comes from emacs.
I've tried to change function names, variables names, but nothing worked.
Does anybody see what's wrong here ?
You need to evaluate the first line of your program before the second.
The interpretor doesn't know the definition of carre or bis until you've evaluated it.

Puzzling error with script run in function

I'm experiencing a puzzling error in Matlab R2012b. It seems that variable names that are also data types exhibit strange behavior. Please see this small example:
function [] = test1()
dataset = 1;
if dataset ~= 0
disp hello
end
end
A call to test1() produces output hello, as expected.
Now, rather than set the value of dataset in my function, I run a script instead.
function [] = test2()
myscript;
if dataset ~= 0
disp hello
end
end
where myscript.m has one line:
dataset=1;
Now, when I call test2() I get this error:
Undefined function 'ne' for input arguments of type 'dataset'.
Error in test2 (line 4)
if dataset ~= 0
(Forgive the variable named dataset - I know that it is also the name of a data type, and it came in the code I was running.) So it seems as if in test2, Matlab creates an empty dataset object rather than using the variable named dataset. Furthermore, this behavior only appears when I set the value in a script rather than in the function body. Even more weird, is that I can do:
>> dbstop in test2 at 4 % line of if statement
>> test2()
K>> dataset
dataset =
1.00
K>> dataset ~= 0
ans =
1
K>> if dataset ~= 0, disp hello; end
hello
K>> dbcont
and I get the same error! The error is not displayed in debugging mode but it is in normal execution.
Can anyone reproduce this? What is going on here?
The MATLAB online help has some pages dealing with this issue; Variables Names and Loading Variables within a Function seem to be the most relevant.
There is no explicit page that discusses how MATLAB resolves names at compilation time, but there is one little tidbit at the bottom of the Variables Names page: "In some cases, load or eval add variables that have the same names as functions. Unless these variables are in the function workspace before the call to load or eval, the MATLAB parser interprets the variable names as function names."
In other words, if the parser finds an explicit assignment to a variable whose name is the same as another existent object, the local definition takes precedence.
In your test2(), there is no explicit assignment to a variable dataset; therefore, when the file is compiled, the parser interprets dataset to be a class constructor (since the parser will not run or inline myscript into the function).
Then at run-time, even though a variable named dataset has been poofed1 into the function's workspace, the interpreted code that is running still has the dataset symbol in the if-statement associated with the class constructor.
If you need to, you can still use the dataset variable name and load from an external file, but it should be done with an explicit assignment via a function call. For example:
dataset = initialize();
Now the parser will notice that dataset is some arbitrary output of the function initialize and all will be well. In fact, you can have even have initialize return a dataset constructor to the dataset variable if you wanted.
1 When variables are defined without explicit assignment, MATLAB people (at least on some of their blogs I've read) called this 'poofing'. Using load without any output arguments, using eval, and simply running scripts (not functions) can all poof variables into the workspace. This can work fine as long as the variable names do not conflict with other in-use symbols at compile time.

Unexpected matlab expression in function

I have the following call to a function:
callfun(I1, I2, [X Y ones(n,1)], w, m)
But, I'm getting:
Error: File: callfun.m Line: 20 Column: 3
Unexpected MATLAB expression.
Why is that?
Thanks.
The error says, that your function callfun has a syntax error in line 20. Probably some character which is not allowed.
It can be also a problem of duplicated function definition. A function inside callfun.m may have the same name as a built-in MATLAB function, what yields an error.
From http://www.mathworks.com/matlabcentral/answers/214993-how-to-solve-error-unexpected-matlab-expression-workspacefunc-287:
Do you have any user-defined functions called builtin, strjoin, or strsplit? MATLAB has these defined internally, and having any outside functions that shadow these built-in ones would result in this error. If you are unsure if you have created such functions, typing the command:
>>which functionName -all
will show you the path to all items on the MATLAB path with the name "functionName"

Octave : Index exceeds matrix dimensions

I wrote the following function in a file named conditionals.m:
function result = conditionals(category, feature)
result=5;
end
I call this function from Octave's command line:
v=conditionals(3,4)
I get the following error:
error : A(I) : Index exceeds matrix dimension.
Whats wrong here?
The error:
error : A(I) : Index exceeds matrix dimension.
Indicates that octave thinks that conditionals is a matrix, not a function.
Octave probably doesn't know that conditionals is a function - and instead it's treating it as a matrix.
Have you checked to see if the function is in Octave's search path?
This works for me.
octave> function result = conditionals (category, feature)
> result = 5;
> endfunction
octave> v = conditionals (3, 4)
v = 5
The error suggests that you have a variable with the same name as the function. Type whos at the Octave prompt to see a list of defined variables. If you see one named conditionals, remove it with clear conditionals
Also, if conditionals is a conditionals.m file, make sure it's on the function search path. Run path at the Octave prompt to see the function search path. Run which conditionals at the command prompt to see where the function is located.
It happened to me as well and it can happen on any command, regardless of the command name. When I run the PS1(">>"); to change the command prompt in Ovtave, I got the same error.
octave-3.2.3.exe:9> PS1(">>");
error: A(I): Index exceeds matrix dimension.
As others also mentioned, this error fires when there is a parameter with the same command name. It happens when we mistakenly enter the command with wrong syntax and hence, octave run the command and produce a variable with your command name that overload the internal command.
You can verify this status by who command. If you can see the same variable name as your command here, you have to remove it. Use clear variable_name to remove the variable.
Here is my output for PS1 command.
Hope it helps.