フィルターのクリア

Finding peaks and troughs of sinusoidal from a Matrix and elements bounded within

2 ビュー (過去 30 日間)
Nkenna Amadi
Nkenna Amadi 2018 年 7 月 3 日
編集済み: jonas 2018 年 7 月 4 日
Hello i have a matrix that consists of zeros and ones. It has 5 sinusodial shapes linked together as seen in the image attached. The yellow represents where the value of the matrix is one and the blue for zero. How do i find the peaks and troughs of each of this sinusodial shapes and the indices/elements(rows and columuns) bounded by each of these sinusodial shapes. Basically i should have something that gives the peak and trough for sinusodial one and then the elements within it

採用された回答

jonas
jonas 2018 年 7 月 3 日
編集済み: jonas 2018 年 7 月 3 日
Since you did not attach the data, I had to start from your attached image. Therefore my x- and y-values are not scaled correctly. Basically you get the coordinates with find() and then findpeaks() to locate peaks and troughs. See attachment for results.
%%Fix binary image
RGB=imread('pic.png');
GRAY = rgb2gray(RGB);
threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);
%Crop edges
BW=BW(5:end-10,60:end-30);
imshow(BW)
%%Find coordinates of ones
[y,x]=find(BW==1)
%%Find peaks and troughs
[~,locs1]=findpeaks(y.*-1,'minpeakprominence',20,...
'minpeakdistance',50)
[~,locs2]=findpeaks(y,'minpeakprominence',20,...
'minpeakdistance',50)
%%Plot data
figure;
plot(x,y,'-',...
x(locs1),y(locs1),'-x',...
x(locs2),y(locs2),'-x')
  7 件のコメント
Nkenna Amadi
Nkenna Amadi 2018 年 7 月 4 日
thank you very much ! how do i find the elements within each of these 5 sinusoids?
jonas
jonas 2018 年 7 月 4 日
編集済み: jonas 2018 年 7 月 4 日
Simple enough. The peak indices are stored in locs2 (troughs) and locs1 (peaks). So, to find the indices between the first two troughs, you can type:
wave1=x(locs2(1):locs2(2))
then for the next
wave2=x(locs2(2):locs2(3))
and so on. If you want the corresponding y-values, just change x to y.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by