First of all i just want to say thank you for your time.
The code that you made works perfectly, but the only think that is missing
is how to do the iterations. I tried to do for me and not bother you but im stiil a noob in vectorization.
I want to show you an exemple and the values that i should obtain. (in the case below there are 2 iterations) and the stopping criterion for the iteration is when the data set has only 3 values. In this case when length(v)=3;
%Inicialization with the data set:
v=[28 -18 8 2 22 -6 20 8 20 -18 22 -4 26 12 30]';
N=length(v);
a=v;
f1=[0; v(1:end-3)~=v(3:end-1)];
f2=[0 ; v(1:N-3)<=v(3:N-1) & v(3:N-1)<v(2:N-2) & ...
v(2:N-2)<=v(4:N)];
f3=[0 ; v(1:N-3)>=v(3:N-1) & v(3:N-1)>v(2:N-2) & ...
v(2:N-2)>=v(4:N)];
g(:,1)=double(f1&(f2|f3));
ix=find(f1&(f2|f3));
S=abs(diff(v));
g(ix,2)=S(ix);
a([ix ix+1])=[];
ix:3 g:0 0 a: 28
7 0 0 -18
11 1 6 22
13 0 0 -6
0 0 20
0 0 -18
1 12 30
0 0
0 0
0 0
1 26
0 0
1 14
%1st iteration
a=v;
v=[28 -18 22 -6 20 -18 30]';
and the process repet for a this new v value.
ix:4 g:0 0 a: 28
0 0 -18
1 6 22
1 26 -18
0 0 30
0 0
1 12
0 0
0 0
0 0
1 26
0 0
1 14
%2nd iteration
a=v;
v=[28 -18 22 -18 30]';
ix:2 g:0 0 a: 28
1 40 -18
1 6 30
1 26
0 0
0 0
1 12
0 0
0 0
0 0
1 26
0 0
1 14
%Stopping criterion
a=v;
length(v)=3
Thank you in advance one more time for you time.
You are helping me a lot.
Greetings
Fagner
The code that you made works perfectly, but the only think that is missing
is how to do the iterations. I tried to do for me and not bother you but im stiil a noob in vectorization.
I want to show you an exemple and the values that i should obtain. (in the case below there are 2 iterations) and the stopping criterion for the iteration is when the data set has only 3 values. In this case when length(v)=3;
%Inicialization with the data set:
v=[28 -18 8 2 22 -6 20 8 20 -18 22 -4 26 12 30]';
N=length(v);
a=v;
f1=[0; v(1:end-3)~=v(3:end-1)];
f2=[0 ; v(1:N-3)<=v(3:N-1) & v(3:N-1)<v(2:N-2) & ...
v(2:N-2)<=v(4:N)];
f3=[0 ; v(1:N-3)>=v(3:N-1) & v(3:N-1)>v(2:N-2) & ...
v(2:N-2)>=v(4:N)];
g(:,1)=double(f1&(f2|f3));
ix=find(f1&(f2|f3));
S=abs(diff(v));
g(ix,2)=S(ix);
a([ix ix+1])=[];
ix:3 g:0 0 a: 28
7 0 0 -18
11 1 6 22
13 0 0 -6
0 0 20
0 0 -18
1 12 30
0 0
0 0
0 0
1 26
0 0
1 14
%1st iteration
a=v;
v=[28 -18 22 -6 20 -18 30]';
and the process repet for a this new v value.
ix:4 g:0 0 a: 28
0 0 -18
1 6 22
1 26 -18
0 0 30
0 0
1 12
0 0
0 0
0 0
1 26
0 0
1 14
%2nd iteration
a=v;
v=[28 -18 22 -18 30]';
ix:2 g:0 0 a: 28
1 40 -18
1 6 30
1 26
0 0
0 0
1 12
0 0
0 0
0 0
1 26
0 0
1 14
%Stopping criterion
a=v;
length(v)=3
Thank you in advance one more time for you time.
You are helping me a lot.
Greetings
Fagner