I ran into an issue today whereby Matlab did NOT throw an error, but I wish it had. I had a 1D array, and I wanted to get just the values corresponding to a few logical true indices, like this:
x = 1:10;
ind = logical([1 0 0 1 0]);
y = x(ind)
y =
1 4
The problem here is I made a mistake: The dimensions of the ind array don't match the dimensions of x, yet Matlab still gave me some numbers anyway. Of course if I let the dimensions of ind exceed the dimensions of x, Matlab appropriately throws an error:
ind = logical([1 0 0 1 0 0 0 0 0 0 1]);
>> x(ind)
The logical indices contain a true value outside of the array bounds.
So why doesn't Matlab throw an error if the dimensions of ind are smaller than the dimensions of x? Is this a bug, or is there some value that I'm not seeing?
0 Comments
Sign in to comment.