Elements of matrix after an equation

1 view (last 30 days)
Stefan Juhanson
Stefan Juhanson on 22 Apr 2021
Edited: Matt J on 22 Apr 2021
Hi! Previosuly i got help from here with this code:
A2 = zeros(size(A,1),1);
iA2 = 0;
for iA = 1:size(A,1)
num = A(iA,1) * A(iA, 2);
if num < 0
iA2 = iA2 +1;
A2(iA2) = num;
end
end
A2 = A2(A2 < 0)
which creates a matrix with elements that are only negative. Now further i have this line:
Pmax = max(abs(A2))
Which takes out the single maximum value from A2. Now the question is can i bring out the matrix elements that value?
In short i need A(iA,1) and A(iA, 2) from Pmax = max(abs(A2))
  1 Comment
Stefan Juhanson
Stefan Juhanson on 22 Apr 2021
Edited: Stefan Juhanson on 22 Apr 2021
Other solutions to the first part were:
A2 = A(:, 1) .* A(:, 2);
A2 = A2(A2 < 0);
or
index = (A(:, 1) < 0) ~= (A(:, 2) < 0);
A2 = A(index, 1) .* A(index, 2)
Basically i need A(index, 1) and A(index, 2) while abs(A(index, 1) .* A(index, 2)) = max
If this helps to give a solution to my problem of finding those elements.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 22 Apr 2021
Edited: Matt J on 22 Apr 2021
p = A(:, 1) .* A(:, 2);
index=(abs(p)==norm(p,inf)) & p<0;
a1=A(index,1);
a2=A(index,2);

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!