How do I maintain my array size (or dimensions) when I run it through a nested for loop?
显示 更早的评论
Hi All,
I have an array, 'data' (5x16x2), that I have shifted to the left (by 1 column) and zero-padded the right accordingly. However, when I run my variable through a nested for loop, my 3d array gets transformed to 2d (5x32). I'm facing some trouble trying to figure out how to maintain my array size as I run it through the nested for loop. I essentially want my 'dataShift' varible to be the same size as my 'data' variable (5x16x2).
My code looks like this:
%dummy data
for ii = 1:2
for i=1:16
data(:,i,ii)=i(:,:);
end
end
%constant variables
sink = 8;
layerIV = 7;
shift = abs(layerIV - sink);
%shift data
for ii = 1:2
for ch = 1:16
if sink > layerIV
dataShift = [data(:, shift+1:end), zeros(size(data,1),shift)];
end
end
end
I thought that perhaps the following might work:
dataShift(:,ch,ii) = [data(:, shift+1:end), zeros(size(data,1),shift)];
But I get the following error: "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-32."
Would really appreciate any help.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!