MATLAB: Rearrange the G matrix

matrix manipulation

Dear
I plot each point in freq. domain and I did ifft.
f=0:1/1024:1;
t=0:1/1024:1;
a=10;
for i=1:1025
if f(i)>=25/1024 && f(i)<=100/1024
v(i)=a;
else
v(i)=0;
end
end
figure;
plot(f,v);
for i=1:1025
G(i)=0;
for j=1:1025
G(i)=v(j).*cos(i*j*2*pi/1025)+G(i);
end
end
figure;
plot(t,G)
Now I would like to rearrange the G matrix so that the last half of points are put as the first half and the first half as the last half (i.e. the biggest point is now in the middle.
regards
Dhafer

Best Answer

add this code
n=floor(size(G,2)/2)
if n==size(G,2)/2
out(1:n)=G(n+1:end);out(n+1:2*n)=G(1:n)
else
out(1:n)=G(n+2:end);
out(n+1:2*n+1)=G(1:n+1);
end
figure;plot(t,out)
Note: in your case length(G)=1025 is odd, i added a test when it's even
Related Question