Simple find and replace program

조회 수: 2 (최근 30일)
Frederik Theissen
Frederik Theissen 2016년 5월 30일
댓글: Walter Roberson 2016년 5월 30일
I have a long list of values (rest time measurements of wild animals) where each row constitutes a 2 second time bin. Measurement was done in 250ms intervals so that the resulting data looks something like this:
0
2
1,75
0,75
2
2
2
0,25
0,75
...
I need to create a program that does the following:
  1. Find the first instance of "2"
  2. Check if there is a "2" right next to it
  3. If yes, move to the value below/above (i.e.: find both non-2 neighbours)
  4. Check if the sum of the two non-2 neigbours >=2
  5. If yes, replace the largest one with a 2 and the smallest one with a 0
  6. If no, ignore and move on
  7. If both non-2 neighbours =1, replace randomly
  8. Move on to the next instance of "2"
I tried to start coding this, but I am getting stuck within these nested for loops, and using the find function. I feel like there is a much easier way to do this, and maybe someone can start me on the right path?
count = 1
for i= 1:length(List) %For the length of the data list
if List(i,1) == 2 %If row i (1,2,3,4,5...) equals 2
count = count+1
%check if the neighbours also = 2
%Start a counter to check how high up it has to go.
if List(count,1) < 2 %Until the
find(List(Count,1)
end
end
end
Thanks,
Fry
  댓글 수: 2
Stephen23
Stephen23 2016년 5월 30일
편집: Stephen23 2016년 5월 30일
@Frederik Theissen: Can you please give us complete input and output example vectors, so that we have something to run our code on and compare the output against.
Walter Roberson
Walter Roberson 2016년 5월 30일
Is the "0,75" intended to represent 3/4, which MATLAB would write as 0.75 ? Or is "0,75" intended to be a pair of values, [0 75] ?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by