Simple find and replace program

2 visualizzazioni (ultimi 30 giorni)
Frederik Theissen
Frederik Theissen il 30 Mag 2016
Commentato: Walter Roberson il 30 Mag 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 Commenti
Stephen23
Stephen23 il 30 Mag 2016
Modificato: Stephen23 il 30 Mag 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 il 30 Mag 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] ?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Big Data Processing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by