How to use a formula for all elements of matrix?
8 ビュー (過去 30 日間)
古いコメントを表示
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
2016 年 7 月 19 日
編集済み: Azzi Abdelmalek
2016 年 7 月 19 日
This is not clear,
Mij(v,u)-Mij(v,u)) is equal to 0
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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 Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!