Could you please explain the code
조회 수: 8 (최근 30일)
이전 댓글 표시
ac= 1:792;
댓글 수: 1
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
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!