我怎样才能找到在MATLAB阵列最小值? [英] How can I find minimum values from array in matlab?
本文介绍了我怎样才能找到在MATLAB阵列最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要提取的两个点(即它们的值),这都标有图黑色轮廓。这些最小值点是2和5。然后提取后这些标记点坐标欲计算它们之间的距离。
在code,我用绘制图像的平均值,计算出最低高度和位置是
I1 = imread('open.jpg');
I2 = rgb2gray(I1);
图中,标题('开');
图(1:尺寸(I2,1),平均(I2,2));
等一下
horizontalAverages =平均(I,2);
图(1:尺寸(I2,1),horizontalAverages)
[最低高度LOCS = findpeaks(-horizontalAverages)
图(LOCS,-1 *最低高度,R *)
极小
-86.5647
-80.3647
-81.3588
-106.9882
-77.0765
-77.8235
-92.2353
-106.2235
-115.3118
-98.3706LOCS = 三十
34
36
50
93
97
110
121
127
136
解决方案
使用了findpeaks功能,如果有信号处理工具箱。
[Y,LOCS] = findpeaks(-x)
会发现局部极小。这个函数有一吨的选项,以处理各种特殊情况,所以是非常有用的。
I want to extract the two points (i.e 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.
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
解决方案
Use the 'findpeaks' function, if you have the signal processing toolbox.
[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.
这篇关于我怎样才能找到在MATLAB阵列最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文