【发布时间】:2016-03-09 17:19:41
【问题描述】:
我正在尝试在 MATLAB 中创建一个循环代码,以“填充”大小为 l x 1 的空列向量中的元素,称为 m。由于我在 MATLAB 方面没有太多经验,我不确定这是否是正确的方法。
注意:由于i属于matlab中的复数,我将数组的第i个元素表示为ii-th 元素。
l=length(A); %The number of rows in the empty vector we seek as our output;
%so as to preallocate space for this vector.
q=eigencentrality(A);%An lx1 column vector whose ii-th elements are used in the loop.
l1=max(eig(A)); %A scalar used in the loop.
CS=sg_centrality(A); %%An lx1 column vector whose ii-th elements are used in the loop.
%Now for the actual loop that will "fill up" each ii-th entry
%of our empty vector, m.
m=NaN(l,1); %create the empty vector to be "filled up".
for ii=1:l
m(ii,:)=log(q(ii)^2)*sinh(l1)/CS(ii)^1/2;%this is the form that I want each entry
%of m to have. Note how the ii-th element
%of m depends on the corresponding ii-th
%element of CS and q!
end
这是“填充”这样一个空列向量的正确方法吗,m,其条目取决于上述其他两个向量的对应元素?
干杯!
【问题讨论】:
-
这可能更适合 Code Review ,因为这似乎是函数代码。
-
写虚数单位的recommended way是
1i或1j。 -
@beaker 关键是,如果您的所有其他代码始终遵循使用
1i的推荐做法,而不是假设i是虚数单位,那么它会更健壮。 -
@200_success 我承认
l1看起来令人困惑,但它实际上是ELL-ONE,而不是虚构的单位1i。事实上,代码中没有任何内容引用虚数单位......也许l1应该重命名为其他东西。
标签: matlab loops for-loop vector vectorization