minimum output matrix from data

2 views (last 30 days)
ANAND ASP
ANAND ASP on 11 Jan 2021
Answered: Ive J on 11 Jan 2021
i have A matrix and i want B matrix as output
A=[ 0 2.8284 5.6569;
2.8284 0 2.8284;
5.6569 2.8284 0;
1.4142 3.1623 5.8310;
5.0000 2.2361 1.0000]
B=[1 1;
2 2;
3 3;
4 1;
5 3]
logic is, In 1st row has minimum number is 0, zero belongs to 1st column so output is 1
In 2nd row has minimum number is 0, zero belongs to 2st column so output is 2
In 3rd row has minimum number is 0, zero belongs to 3st column so output is 3
In 4th row has minimum number is 1.4142, 1.4142 belongs to 1st column so output is 1
In 5th row has minimum number is 1, 1belongs to 3st column so output is 3
in B martrix 1st column is serial number and 2nd column is output.

Accepted Answer

Ive J
Ive J on 11 Jan 2021
A=[ 0 2.8284 5.6569;
2.8284 0 2.8284;
5.6569 2.8284 0;
1.4142 3.1623 5.8310;
5.0000 2.2361 1.0000];
[~, minIdx] = min(A, [], 2);
B = [(1:size(A, 1))', minIdx]

More Answers (0)

Categories

Find more on Multidimensional 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!