当前位置:首页>开发>正文

matlab编程中的序列翻转移位指令。 matlab 数组位移

2023-04-22 14:39:55 互联网 未知 开发

 matlab编程中的序列翻转移位指令。 matlab 数组位移

matlab编程中的序列翻转移位指令。

(1)、矩阵循环移位:circshift
例如:b = circshift(a,[x,y]) 其中a为待移位的矩阵,x表示上下移位位数(正数表示向下移位),y表示左右移位位数(正数表示向右移位)
>> x = [1,2,34,5,67,8,9]
x =
1 2 4 5 7 8 >> y = circshift(x,[1,-1])
y =
8 9 2 3 5 6 (2)、比特移位:bitshift(不能做循环移位)
例如:b = bitshift(a,k,n) 其中a是待移位数据,k是移位的位数(正数表示左移),n为移位后保留的位数(当左移,超出的位数将被舍弃)
>> x = 131
>> x_bit = dec2bin(x)
x_bit =
1000001>> y = dec2bin(bitshift(x,2,8))
y =
1100

matlab 数组位移

x1_shift_right1(1:10) = 0 %%% 给x1_shift_right1赋初始值,全部为0
结果:
x1_shift_right1 =
0 0 0 0 0 0 0 0 0 0

x1_shift_right1(2:10) = x1(1:9) %%%% 将x1的第1到9个数值赋值给x1_shift_right1第2 到第10个值

>>x1=randint(1,10,[0,10])
x1 =
9 9 5 10 3 5 8 0 0 >> x1_shift_right1(2:10) = x1(1:9)

x1_shift_right1 =
0 9 9 5 10 3 5 8 0 0

最新文章

随便看看