I have one 194-by-1 matrix. When I try to find its size, I get this message:
Subscript indices must either be real positive integers or logicals.
All values are positive and logical, what is the problem?
I have one 194-by-1 matrix. When I try to find its size, I get this message:
Subscript indices must either be real positive integers or logicals.
All values are positive and logical, what is the problem?
Is it possible that you accidentally override the size
function?
>> which size
Should give this output
built-in (C:\ X X X \toolbox\matlab\elmat\size)
If you get something like
size is a variable
Then you override the function.
To ammend this you'll have to clear
the variable
>> clear size
Now you can use the function
>> size( A )
Can you provide your code? It should work if you do it like this:
[rows cols] = size(A);
or
rows = length(A);
In MATLAB, size
is a function that returns the dimensions of an array (a matrix, a cell array, etc...). However, MATLAB also supports overloading. When you call size(A)
(assuming A
is your matrix), the MATLAB interpreter first checks if there are overloaded variables/functions with the name size
.
Apparently you have a variable named size
, judging by the error message, so for MATLAB size(A)
means that your trying to index into the matrix size
with the subscript variable A
. It seems that A
has one or more zero elements, and since non-positive indices in MATLAB are forbidden, this triggers the aforementioned error.
The simplest solution is to use another name for your variable size
so you can call the built-in function size
without any issues.