我收到此错误
指数超出矩阵维度
当我在MATLAB中运行以下内容时。我做错了什么?
>> a
a =
1 2 3
4 5 6
7 8 9
>> a(:)
ans =
1
4
7
2
5
8
3
6
9
>> sum(a(:))
Index exceeds matrix dimensions.
>> sum(a(:),1)
Index exceeds matrix dimensions.
>> sum(a(:),2)
Index exceeds matrix dimensions.
答案 0 :(得分:3)
您确实在名称sum
a = [1 2 3 ; 4 5 6; 7 8 9]
sum = 1;
>> sum(a);
Index exceeds matrix dimensions.
clear sum;
>> sum(a)
ans =
12 15 18