"end + 1"行在这里做什么? [英] What is the `end+1` line doing here?

查看:107
本文介绍了"end + 1"行在这里做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下MATLAB代码:

Consider the following bit of MATLAB code:

degree = 6;
out = ones(size(X1(:,1)));
for i = 1:degree
    for j = 0:i
        out(:, end+1) = (X1.^(i-j)).*(X2.^j);
    end
end

我不确定我看到end+1索引如何运行.此代码中没有以前定义的名为end的变量.

I'm not sure I see how the end+1 index is functioning. There are no previously defined variables called end in this code.

推荐答案

end编写为下标等效于按照

Writing end as a subscript is equivalent to writing the index of last element in the array in the specified dimension, as stated in the official documentation:

end函数还用作索引表达式中的最后一个索引.
在这种情况下,end = (size(x,k))用作第k个索引的一部分.这种用法的示例是X(3:end)X(1,1:2:end-1).当使用end增长数组时,如在X(end+1)=5中一样,请确保首先存在X.

The end function also serves as the last index in an indexing expression.
In that context, end = (size(x,k)) when used as part of the kth index. Examples of this use are X(3:end) and X(1,1:2:end-1).When using end to grow an array, as in X(end+1)=5, make sure X exists first.

在您的情况下(以粗体突出显示),out(:, end+1)表示矩阵outi的每次迭代中都在第二维中增长.

In your case (highlighted in bold), out(:, end+1) means that the matrix out is growing in the second dimension with each iteration of i.

这篇关于"end + 1"行在这里做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆