Need Help Urgent!!!!!!!!!!!!
1 view (last 30 days)
i have this data in matrix X=[22,33,11,33,33,33,22]
i want to change the data with this form of matrix X=[22,33,22,33,33,33,44]
i have to follow this rules: 1)when find(X==33) next data must change into 22 2)when there have data "33" three times in row,the next data must change to 44
this is my example code for the looping: [a b]=find(X==33)
if X(a,b+1)-X(a,b)==1 if X(a,b+2)-X(a,b+1)==1 X(a,b+3)=44 end end
if X(a,b+1)-X(a,b)==2 X(a,b+2)=22 end
i know im doing this all wrong,can someone give a correct algorithm to get the answer that satisfied the rules.
Amir my email: email@example.com
Matt Fig on 28 Mar 2011
You did not completely clarify, but here is a non-vectorized code that will do part of the job. Note that for this problem, it might be quicker to use a loop anyway.
cnt = 1;
Y = X==33;
while cnt <= length(X)-2
if Y(cnt+1:cnt+2) % Three in a row.
X(cnt+3) = 44;
cnt = cnt + 4;
elseif Y(cnt+1) % Two in a row.
X(cnt+2) = 11;
cnt = cnt + 3;
else % Just one 33.
X(cnt+1) = 22;
cnt = cnt + 2;
cnt = cnt + 1;