我正在尝试连接 1->(a-1) + (a+1)->n 中的数字数组。
我正在使用 cat 函数
cat(2, 1:a-1, a+1:n)
但是我得到了错误
Index exceeds matrix dimensions.
除非我完全弄错了,否则我只是想连接两个数字矩阵,所以我不太确定为什么会收到此错误。
我正在努力做到这一点:
>> a = 3;
>> n = 10;
>> cat(2, 1:a-1, a+1:n)
ans =
[1,2,4,5,6,7,8,9,10]
这是错误的做法吗?知道为什么会出现此错误吗?
最佳答案
您的工作区中是否有一个名为 cat
的变量?
>> 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.
关于Matlab cat() 函数 : index exceeds matrix dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12784564/