Error: ()-indexing must appear last in an index expression. Which is the problem in line 4?? Help me pls
1 次查看(过去 30 天)
显示 更早的评论
function [A] = SecondTypeStirlingNumber(i,n) A=zeros([i n]); for j=1:n A(j)(j)=1; for k=2:i A(j)(k) = A(j-1)(k) + k*A(j)(k); end end end
0 个评论
回答(1 个)
Sumeet Gadagkar
2018-3-6
Hey Carlo,
While trying to index matrices in MATLAB the syntax is A(i,j) assuming 'A' is your matrix, not A(i)(j). You should also note that MATLAB indexes start from 1 and not 0, so something like A(0,0) or A(0,1) or A(2,0) will give an error which is the case for your code in line 6 in the first iteration of the for loop. Consider indexing such that a 0 index does not occur. The code is as below with the correct syntax for indexing a matrix.
function [A] = SecondTypeStirlingNumber(i,n)
A=zeros([i n]);
for j=1:n
A(j,j)=1;
for k=2:i
A(j,k) = A(j-1,k) + k*A(j,k);
end
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!