find same numbers in a row

조회 수: 3 (최근 30일)
twan Zwetsloot
twan Zwetsloot 2019년 10월 4일
댓글: Image Analyst 2019년 10월 25일
Hello masters of MATLAB,
I am writing a script for a assigement of my study. I have a signal where I have to find places where 30 samples in a row are 0 or 1. The true or false are if the player is higher or lower than the walkingspeed of a player.
How could I find these sports. It is plotted in a line graph with at the x-axis the time and at y-axis the speed of the player.
Can someone help me?
  댓글 수: 3
twan Zwetsloot
twan Zwetsloot 2019년 10월 25일
If you get this vector as underneath. You want to only have the one that are more or equal to five in this example. Do you know how to solve this?
1
1
1
0
0
1
1
0
0
0
0
0
1
1
1
1
1
1
1
1
1
Image Analyst
Image Analyst 2019년 10월 25일
As I showed, you can use regionprops(). But you have not said exactly what you want as the output. What EXACTLY do you want? A vector with only the long stretches in there? The location of the 1's? The location of the starting index of each long stretch? What?????

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillermo Rubio Gomez
Guillermo Rubio Gomez 2019년 10월 4일
Assuming you have the time vector and the 0 and 1 vectors, to obtain the times corresponding to 0's and 1's:
ceros_time = t(y==0); % Vector with times correponding to 0's in the y vector
ones_time = t(y==1); % Vector with times correponding to 1's in the y vector

Image Analyst
Image Analyst 2019년 10월 4일
You can do this if you have the Image Processing Toolbox:
props = regionprops(yourSignal, 'PixelIdxList', 'Area');
allLengths = [props.Area]; % Get all lengths into a list.
% Extract only where they are 30 long or longer.
goodIndexes = allLengths >= 30;
props = props(goodIndexes);
% Print out where they start and stop
for k = 1 : length(props)
fprintf('Run #%d starts at index %d and stops at index %d', k, props(k).PixelIdxList(1), props(k).PixelIdxList(end))
end

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by