MATLAB Answers

# minimum output matrix from data

1 view (last 30 days)
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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

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]
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!