简体   繁体   English

如何在Matlab中从数组中找到最小值?

[英]How can I find minimum values from array in matlab?

图片

I want to extract the two points (ie their values) which are marked with black outline in figure. 我想提取图中用黑色轮廓标记的两个点(即它们的值)。 These minima points are 2 and 5. Then after extraction these marked points coordinates I want to calculate the distance between them. 这些最小点是2和5。然后在提取这些标记点的坐标后,我要计算它们之间的距离。

The code that I am using to plot average values of image, calculate minimas and locations is 我用来绘制图像平均值,计算最小值和位置的代码是

I1=imread('open.jpg');
I2=rgb2gray(I1);
figure, title('open');
plot(1:size(I2,1), mean(I2,2));
hold on
horizontalAverages = mean(I2 , 2);
plot(1:size(I2,1) , horizontalAverages)
[Minimas locs] = findpeaks(-horizontalAverages) 
plot(locs , -1*Minimas , 'r*')

Minima 极小值

-86.5647
-80.3647
-81.3588
-106.9882
-77.0765
-77.8235
-92.2353
-106.2235
-115.3118
-98.3706

locs =

    30
    34
    36
    50
    93
    97
   110
   121
   127
   136

It is a bit unclear from your question what you are actually looking for, but the following one liner will get you the local minima: 从您的问题中尚不清楚您真正要寻找的是什么,但是下面的划线员将为您提供当地的最低要求:

% Some dummy data
x = 1:11;
y = [3 2 1 0.5 1 2 1 0 1 2 3];

min_idx = ([0 sign(diff(y))] == -1) & ([sign(diff(y)) 0] == 1);

figure
plot(x, y);
hold on;
scatter(x(min_idx), y(min_idx))
hold off;

在此处输入图片说明

Use the 'findpeaks' function, if you have the signal processing toolbox. 如果您具有信号处理工具箱,请使用“ findpeaks”功能。

[y,locs]=findpeaks(-x) 

will find the local minima. 会找到当地的最小值。 This function has a ton of options to handle all kinds of special cases, so is very useful. 此功能有很多选项可以处理各种特殊情况,因此非常有用。

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

相关问题 Matlab:从一组值中为数组中的每一列查找最小值 - Matlab: Find minimum value from a set of values for each column in an array 如何从数组中找到最小值 - How to find minimum values from array 如何在 MATLAB 单元阵列中找到非零值? - How can I find the nonzero values in a MATLAB cells array? 如何排序一个numpy数组以找到最小坐标? - How can I sort a numpy array to find a minimum coordinate? 如何在数组中找到最大和最小日期? - How can I find the maximum and minimum date in an array? 如何在 c++ 中找到数组的最小和唯一元素? - How can I find minimum and unique element of array in c++? 如何在保持最小值的同时缩放值数组? - How can I scale an array of values while maintaining a minimum value? 如何在octave / matlab中找到多维数组中具有相同值的所有单元格 - How can I find all the cells that have the same values in a multi-dimensional array in octave / matlab 在MATLAB中找到与数组元素之间的最小距离 - Find the minimum distance to a number from the elements of an array in MATLAB 如何找到第一个数组中所有值的最后一个大于或等于值的索引? 的MATLAB - How can I find the index of the last greater than or equals value in one array, for all values in the first array? MATLAB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM