Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
How can I do this in matlab?
a = [0 0 1 2 3]
shift to the left and get
a= [0 1 2 3 0]
cheers
>> a=[ 0 1 2 3 0];
>> circshift(a,[1 1])
ans =
0 0 1 2 3
a = [0 0 1 2 3];
x=0; % circular shift up or down. up when positive, down when negative, no shift when 0;
y=-1; % circular shift left or right. right when positive, left when negative, no shift when 0;
a=circshift(a,[x y]);
X = [ 0 0 1 2 3];
X = horzcat(X(i+1:length(X)),zeros(1:i));
Is it possible to this?
first I have matrix X
X = [ 0 0 1 2 3];
and i want to shift it to left and replace the numbers by zero so I get
X = [3 0 0 0 0];
%blooz Shift fill Zero
function y=shift_filzero(x,n)
if n<0
temp1=zeros(1,-n);
temp2=circshift(x,[1 n]);
temp3=[temp2(1:-n),temp1];
else
temp2=circshift(x,[1 n]);
temp3=[zeros(1,n),temp2(1:n)];
end
y=temp3
>> a=[ 0 1 2 3 4 5 6 7];
>> shift_filzero(a,4)
ans =
0 0 0 0 4 5 6 7
>> shift_filzero(a,-4)
ans =
4 5 6 7 0 0 0 0