필터 지우기
필터 지우기

How to use a formula for all elements of matrix?

조회 수: 8 (최근 30일)
Beibit Sautbek
Beibit Sautbek 2016년 7월 19일
댓글: Stephen23 2016년 7월 19일
I have a matrix the
Mij =[ NaN 2.5000 0
2.5000 NaN -0.8333
0 -0.8333 NaN]
And I have a general formula::
phi=atand(abs((m2-m1)/(1+m1*m2)))
I need to use this formula for all elements of my matrix.
For example, I want to use as m2=M12(element in first row and second column)and
as m1=M32 (element in third row and second column). and according the formula
phi=atand(abs((Mij(1,2)-Mij(3,2))/(1+Mij(3,2)*Mij(1,2)));
And I need for all cases, which for all elements in matrix.
Can anyone help me?
I have tried as below, but the result is wrong:
for u=1:E1
for v=1:E1
p(v,u)=abs((Mij(v,u)-Mij(v,u))/(1+Mij(v,u)*Mij(v,u)));
end
end
Result is wrong:
p =
NaN 0 0
0 NaN 0
0 0 NaN
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 19일
편집: Azzi Abdelmalek 2016년 7월 19일
This is not clear,
Mij(v,u)-Mij(v,u)) is equal to 0

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2016년 7월 19일
for u1=1:size(M,1)
for v1=1:size(M,2)
m1 = M(u1,v1);
for u2=1:size(M,1)
for v2=1:size(M,2)
m2 = M(u2,v2);
phi(u1,v1,u2,v2)=atand(abs((m1-m2)/(1+m1*m2)));
end
end
end
end
Best wishes
Torsten.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 7월 19일
M=[NaN 2.5000 0
2.5000 NaN -0.8333
0 -0.8333 NaN];
phi=@(m1,m2)atand(abs((m2-m1)./(1+m1.*m2)));
out1 = bsxfun(phi,M(:),M(:)');
out2 = reshape(out1,[size(M),size(M)]);

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by