Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab cat() function: index exceeds matrix dimensions

I am trying to concatenate an array of numbers from 1->(a-1) + (a+1)->n.

I was using the cat function

cat(2, 1:a-1, a+1:n)

but I am getting the error

Index exceeds matrix dimensions.

Unless I am completely mistaken, I am just trying to concatenate two matrices of numbers so I'm not quite sure why I'm getting this error.

I'm trying to accomplish this:

>> a = 3;
>> n = 10;
>> cat(2, 1:a-1, a+1:n)
ans = 
    [1,2,4,5,6,7,8,9,10]

Is this the wrong way to do it? Any idea why this error is coming up?

like image 783
user1653208 Avatar asked Jul 29 '26 20:07

user1653208


1 Answers

Do you have a variable called cat in your workspace?

>> cat(2, 2:3, 4:6)                   # this works fine
ans =
     2     3     4     5     6
>> cat = 1:3;                         # introduce the variable 'cat'
>> cat(2, 2:3, 4:6)                   # now it breaks
??? Index exceeds matrix dimensions.
like image 158
Chris Taylor Avatar answered Aug 01 '26 11:08

Chris Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!