[英]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.