【发布时间】:2023-03-10 06:54:02
【问题描述】:
我想非循环移动我的矩阵,然后将零填充到左侧或右侧(取决于移位),即如果矩阵向右移动,零将被填充到左侧。
我使用的是 MATLAB 2019b,到目前为止我的代码如下所示:
%dummy data
data = rand(5, 16);
channelSink = 9; %this variable will either be >layerIV, <layerIV or =layerIV
layerIV = 7;
diff = layerIV - channelSink;
for channel = 1:16
if channelSink > layerIV
%shift columns to the left by ab(diff)
%and
%set columns shifted by ab(diff) to zero
elseif channelSink < layerIV
%shift columns to the right by diff
%and
%set columns shifted by diff to zero
else %idiff = 0, don't shift
diff = 0;
disp('Sink at channel 7; not necessary to re-align');
end
end
提前谢谢你
【问题讨论】:
标签: matlab for-loop if-statement shift