Finding Min Value in array with changing condition
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!