Could you please explain the code

9 views (last 30 days)
HR D
HR D on 18 Aug 2021
Edited: HR D on 18 Aug 2021
ac= 1:792;
  1 Comment
John D'Errico
John D'Errico on 18 Aug 2021
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.

Sign in to comment.

Answers (1)

DGM
DGM on 18 Aug 2021
Edited: DGM on 18 Aug 2021
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

Tags

Products

Community Treasure Hunt

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

Start Hunting!