Nested loop error help
显示 更早的评论
Hello!
I guess this should be super obvious and simple for almost everyone...but for some reason I can't make this nested for loop to work:
I get this error and I'm not sure why: Attempted to access b(1,7); index must be a positive integer or logical.
b = zeros(51,11);
for i = 0:0.01:0.5
for j = 0:0.1:1
a = (2*i)+j;
p = (j/0.1)+1;
q = (i/0.01)+1;
b(q,p)= a;
end
end
Thanks!
采纳的回答
更多回答(2 个)
Image Analyst
2014-3-15
Try this:
b = zeros(51,11);
for i = 0:0.01:0.5
for j = 0:0.1:1
a = (2*i)+j;
p = int32(10*j+1);
q = int32(100*i+1);
b(q,p)= a;
end
end
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!