Effacer les filtres
Effacer les filtres

How to use a formula for all elements of matrix?

8 vues (au cours des 30 derniers jours)
Beibit Sautbek
Beibit Sautbek le 19 Juil 2016
Commenté : Stephen23 le 19 Juil 2016
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 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 19 Juil 2016
Modifié(e) : Azzi Abdelmalek le 19 Juil 2016
This is not clear,
Mij(v,u)-Mij(v,u)) is equal to 0

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 19 Juil 2016
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.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 19 Juil 2016
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)]);

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by