This is Driving Me Crazy: How can I get an index to follow a value, Find the Lowest Value in The Matrix WITHOUT Min and get it to display the Index as the lowest #?

3 次查看(过去 30 天)
I know this matrix below might seem kinda weird, but it's to do with a bigger part of a program I'm testing. I need 3 to be referenced as 511, 4 as 818, 7 as 379 and 8 as 812. I've researched hundreds of solutions but I can't get them to work for my situation.
z = 3 4 7 8
511 818 379 812
I want to be able to find the lowest value which I can see here is 379, but I wish to learn without min for understanding of the logic. Counter intuitive I know, but even with min, I cannot get it to display the index vs the value. Really grinds my gears. I'd appreciate the help.

回答(1 个)

Mehmed Saad
Mehmed Saad 2020-4-13
编辑:Mehmed Saad 2020-4-13
z = [3 4 7 8
511 818 379 812];
when you are using min here, it is comparing rows with each other and giving you min value because it works rowwise
to change it to column type
min(z,[],2)
it will give you
ans =
3
379
if you just want to find the minimum value of 2nd row and it's index
[val,ind] = min(z(2,:))
if you want the corresponding value of 1st Row
z(1,ind)
If you want to the complete column of min
z(:,ind)
In 1 command
z(:,z(2,:)==min(z(2,:)))

类别

Help CenterFile Exchange 中查找有关 Propagation and Channel Models 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by