Finding Min Value in array with changing condition

조회 수: 4 (최근 30일)
Erel Kasirga
Erel Kasirga 2019년 9월 29일
답변: Jos (10584) 2019년 9월 29일
Hello guys,
I got a matrixs which are like ;
a=randi([0,1],1,5)
cost=[6739,10355,7650,5219,5776]
in this changable conditions I want to find the min value.
For example;
a= [1 0 0 0 1]
cost=[6739,10355,7650,5219,5776]
min cost = 5776 according to matrix a

답변 (1개)

Jos (10584)
Jos (10584) 2019년 9월 29일
tf = a == 1 % create a logical array
temp = cost(tf) % logical indexing to retrieve certain values
mincost = min(temp) % use a dedicated function to find th minimum value
I leave it to you to make this a single statement!

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by