array multiplication with a negative value

15 次查看(过去 30 天)
A=[0,-2.2,-3.3,-25;1.2,0,-1.1,12;2,-8,8,0] my answer is to be A=[0,-2.2,-3.3,-25;-1.2,0,-1.1,-12;-2,-8,-8,0]. I need to convert the values in A which is greater than zero as -A. I have used if A(A > 0) A=-A; end This is not working. Suggest some points

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-6-11
编辑:Andrei Bobrov 2014-6-11
t = A > 0;
A(t) = -A(t);
or
A = -abs(A);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by