简体   繁体   English

如何找到负数序列的最小值?

[英]How to find the min value of a sequence of negative numbers?

I have a vector of negative values like this: 我有一个像这样的负值向量:

values = [-15,  -6.45,  -3.75, -5.55, -2.40]

i want to know which of these is the smallest and the corresponding index. 我想知道其中哪个是最小的以及相应的索引。 I try using min function but i ran into this error: 我尝试使用min函数,但是遇到了这个错误:

Subscript indices must either be real positive integers or logicals.

How can i solve this annoying problem? 我该如何解决这个烦人的问题?

I think you are trying to use the direct output of min to access an entry in an array. 我认为您正在尝试使用min的直接输出来访问数组中的条目。 The return value of min is the actual minimum value not the index in the array. min的返回值是实际最小值,而不是数组中的索引。

To get the value and the index try using the following code: 要获取值和索引,请尝试使用以下代码:

values = [-15,  -6.45,  -3.75, -5.55, -2.40];
[minval,minindex] = min(values)

This will return minval = -15 and minindex = 1 . 这将返回minval = -15minindex = 1 With minindex you can address an entry in an array. 使用minindex您可以寻址数组中的条目。 For example in the values -array: 例如,在values -array中:

values(minindex)

This returns of course -15 . 这将返回课程-15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 MATLAB 中找出两个不同向量中的连续数字序列? - How to find out consecutive sequence of numbers in two different vectors in MATLAB? 如何在不使用最小值或特制功能的情况下找到最小值 - How to find a minimum value without using min or specifically made functions 如何找到具有负值的索引并将该值替换为恰好为正的最接近的索引值? - How to find indices with a negative value and replace the value with the nearest index's value that happens to be positive? Matlab查找无限制的最小值 - matlab find min value without constraint 查找给出最小y值的坐标 - Find the coordinate that gives the min y-value 如何在MATLAB中找到序列中的趋势? - How to find a trend in a sequence in MATLAB? 如何在Pytorch中形成一个连续的数字序列? - How to form a sequence of consecutive numbers in Pytorch? 如何以更好的方式在Matlab中显示序列号? - How to display sequence numbers in Matlab in a better way? 如何从字符串中找到负数和正数? - how to find negative and positive number from a string? MATLAB-如何查找值大于零(或在NaN序列之前)的列中的最后一行? - MATLAB - How to find the last row in a column with the value greater than zero (or before sequence of NaNs)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM