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 Center および File ExchangeBig Data Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by