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.
댓글 수: 0
답변 (1개)
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,:)))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Propagation and Channel Models에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!