minimum output matrix from data

2 次查看(过去 30 天)
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.

采纳的回答

Ive J
Ive J 2021-1-11
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 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by