我运行代码"索引超出矩阵维度"出现错误但我不明白为什么。
以下是代码:
function [ p ] = myIsort2(p)
%myIsort2 is based on myIsort but instead of sorting a row vector into
%increasing order it sorts a structure array into decreasing order
global order
n=length(p);
for i=2:n
x=p(1,i).exponent;
y=p(1,i).coeff;
j=i-1;
while (j~=0) && order(x,p(1,j).exponent)==1
%compares the order between 2 row vectors of the exponential field
%in order to sort them by making the smallest one come after the
%largest one
p(1,j+1).exponent=p(1,j).exponent;
p(1,j+1).coeff=p(1,j).coeff;
j=j-1;
end
p(1,j+1).exponent=x;
p(1,j+1).coeff=y;
end
end
感谢。
答案 0 :(得分:2)