Simple find and replace program
2 views (last 30 days)
Show older comments
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:
- Find the first instance of "2"
- Check if there is a "2" right next to it
- If yes, move to the value below/above (i.e.: find both non-2 neighbours)
- Check if the sum of the two non-2 neigbours >=2
- If yes, replace the largest one with a 2 and the smallest one with a 0
- If no, ignore and move on
- If both non-2 neighbours =1, replace randomly
- 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 Comments
Walter Roberson
on 30 May 2016
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] ?
Answers (0)
See Also
Categories
Find more on Big Data Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!