Could you please explain the code

9 次查看(过去 30 天)
HR D
HR D 2021-8-18
编辑: HR D 2021-8-18
ac= 1:792;
  1 个评论
John D'Errico
John D'Errico 2021-8-18
Explain what? Uncommented code that does nothing intelligible is indecipherable. Just a mess of random characters. Especially so since you give us not even a clue as to wht it should be doing, and why it would be of any interest.
ASK THE AUTHOR.

请先登录,再进行评论。

回答(1 个)

DGM
DGM 2021-8-18
编辑:DGM 2021-8-18
John is right. If you don't know what it does conceptually (and certainly the variable naming and lack of comments is no help), then of what use is it to you?
For what it's worth, it just does a bunch of array reshaping.
idx = 1:792; % make a vector
idx = reshape(idx,24,33); % reshape it into a 2D array
% blockwise flip of every 3-column group
idx = idx(:,[3 2 1 4 5 6 9 8 7 10 11 12 15 14 13 16 17 18 21 20 19 22 23 24 27 26 25 28 29 30 33 32 31]);
flp = [0 1 0];
for(i=1:11)
for(j=1:3)
if(flp(j)==1)
% for each block, flip the center column
idx(:,(i-1)*3+j)=idx(end:-1:1,(i-1)*3+j);
end
end
end
tmp = [];
omkeer = ones(1,33); % superfluous
for(i=1:33)
% split each column of idx into two cols (12x2)
tmp2 = reshape(idx(:,i),2,12)';
if(omkeer(i)==1) % always true
tmp2 = tmp2(:,2:-1:1); % flip each 12x2 block left-right
end
tmp = [tmp tmp2]; % reassemble
end
idx2 = tmp; % idx is now 12x66
It could be rewritten:
idx = reshape(1:792,24,3,11); % reshape, blocks arranged on dim3
idx(:,:,1:2:end) = flip(idx(:,:,1:2:end),2); % flip blocks
idx(:,2,:) = flipud(idx(:,2,:)); % flip middle columns
idx = reshape(idx,24,33); % assemble blocks
% do 12x2 blockwise operations
idx = reshape(fliplr(permute(reshape(idx,2,12,33),[2 1 3])),12,66);
and both results should be identical:
immse(idx,idx2)
ans = 0

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by