Matrix calculation without a For loop

1 次查看(过去 30 天)
Hi. Suppose A is a 1D matrix of [1 by N], and D and C are two square matrix of [N by N]. I would like to calculate D and C without a loop such that each element of D and C are calculated using elements of matrix A:
C(i,j)=A(i)*A(j)
D(i,j)=(A(i)+A(j))/C(i,j)
for instance:
C(1,1)=A(1)*A(1)
C(1,2)=A(1)*A(2)
C(1,3)=A(1)*A(3)
etc.
Thank you.

采纳的回答

Roger Stafford
Roger Stafford 2017-5-1
Given the assumption that A is 1 by N, do this:
C = A(:)*A;
D = bsxfun(@plus,A(:),A)./C;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by