Filter löschen
Filter löschen

How to use a formula for all elements of matrix?

8 Ansichten (letzte 30 Tage)
Beibit Sautbek
Beibit Sautbek am 19 Jul. 2016
Kommentiert: Stephen23 am 19 Jul. 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

Akzeptierte Antwort

Torsten
Torsten am 19 Jul. 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.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 19 Jul. 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)]);

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by