MATLAB: Vectors problem

plotscalevectors

Hey Guys !!
I am working with vectors and I read about it before I post my question but can't still get it… Sorry if it is too basic but its difficult for me.. I have four vectors each of size 1×100.. x,y,g,z.. I did plot (x,y) and (g,z) and It is what I expect.. the four vectors are generated randomly so there is low chance the points values will be identical.. I want my first plot to be identical to my second but with leaving the first 3 points, to clear this part I mean usually points starts from point(1,1),(1,2),(1,3) etc but I shall leave those 3 points for the plot(x,y) and start from(1,4) and make it identical to the first point in plot (g,z) so x,y(1,4)= g,z(1,1) and so on.. so basically the two plots are now identical but the first is a shifted version.. I start breaking the steps to achieve this 1. since the vectors are separated in matlab workspace I thought first I need to concatenate the vectors together.. so I created A[x;y] 2×100 and B[g,z] 2×100.(Successful, I did that) 2. I looped through the points in B with ignoring the first 3 points of A and starting from(1,4) and copy the points.. first 3 points set it as NaN(Successful, I did that) 3.I need now to plot my vectors A,B first in two different plots then in same plot to see the result, here is my problem.. I thought by doing the first two steps I can easily plot A and B scale one down then I will be able to see that they the same but one is shifted but that didn't happen..
Is the way I broke down the problem wrong or my last step was not done properly???
Thanks all in advance !!!

Best Answer

See this and check if it's you're looking for:
function princ
lambdaMax=45;
T=50;
x=-2*pi:1/5:2*pi;
lambda =@(x)( sin(x)*(20+30));
S = Trial(lambdaMax,lambda,T)
hold on
% plot(S,lambda(S))
X = linspace(min(S),max(S),100);
Y = pchip(S,lambda(S),X);
Signal1=[X;Y]
plot(X,Y,'b')
lambdaFirst =@(x) (sin(x-4)*(20+30));
S1 = Trial(lambdaMax,lambdaFirst,T);
% plot(S1,lambdaFirst(S1))
X1 = linspace(min(S1),max(S1),100);
Y1 = pchip(S1,lambdaFirst(S1),X1);
Signal2 = [X1;Y1];
plot(X1,Y1,'r')%phase shitf
plot([zeros(1,4) X(1:end-4)],Y1,'black')%delay shift
% Signal1(1,1)= NaN;
% Signal1(1,2)=NaN;
% Signal1(1,3)=NaN;
% Signal1(1,4)=NaN;
% d = 4;
% for i=1:100-d
% Signal1(:,i+4) = Signal2(:,i);
% end
xlabel('t')
ylabel ('cos(x)')
legend('Original','Phase shift','Delay shift')
hold off;
end
function S = Trial(lambdaMax,lambda,T)
t = 0;
I = 0;
S = [];
u = rand;
t = t - log(u)/lambdaMax;
while t <= T
u=rand;
if (u < lambda(t)/lambdaMax)
I = I+1;
S(I) = t;
end
u = rand;
t = t - log(u)/lambdaMax;
end
end