Simple find and replace program

2 Ansichten (letzte 30 Tage)
Frederik Theissen
Frederik Theissen am 30 Mai 2016
Kommentiert: Walter Roberson am 30 Mai 2016
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 Kommentare
Stephen23
Stephen23 am 30 Mai 2016
Bearbeitet: Stephen23 am 30 Mai 2016
@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 am 30 Mai 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] ?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Big Data Processing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by