循环期间矩阵索引超出范围
a
是n
x n
矩阵。
我有此代码:
[m,n] = size(a);
x = zeros(m,1);
for j=1:1:n
if(j==1)
a(1,:) = [];
else
end
disp(a);
a(:,j) = [];
disp(x);
disp(a);
end
它在行上给出了错误a(:,j)= [];
说明
矩阵索引的删除范围不超出范围。
为什么?我不明白,帮助您赞赏。
a
is an n
xn
matrix.
I have this code:
[m,n] = size(a);
x = zeros(m,1);
for j=1:1:n
if(j==1)
a(1,:) = [];
else
end
disp(a);
a(:,j) = [];
disp(x);
disp(a);
end
And it gives error on the line a(:,j) = [];
which says
Matrix index is out of range for deletion.
Why? I dont understand, help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是:
尝试使用:
发生了什么事是您从j = 1开始删除列,因此每次缩短矩阵。一旦j大于剩下的 A中的列数,就会丢弃该错误。
我建议向后迭代解决这个问题(因为您的索引在随着矩阵尺寸的减小而减小)。
Instead of:
Try using:
What's going on is you're deleting columns starting from j=1 and therefore shortening your matrix each time. As soon as j is greater than the remaining number of columns in a, it will throw that error.
Iterating backwards as I am suggesting will solve this problem (because your index is decreasing at the same time as your matrix size is decreasing).