필터 지우기
필터 지우기

Perform Operation Only on Specified Rows.

조회 수: 2 (최근 30일)
Ellie
Ellie 2015년 7월 30일
편집: dpb 2015년 7월 31일
I have attempted to modify this code that circshifts the even rows a specified number of times, however I would like to make it more general, specifically to shift the first row by 0, the second row by N, the third row by N^2 the, then repeat after N times. Any help would be appreciated. Thanks.
A=randi(9,10,4)
N = 3;
for i = 1:N
idx=i:N:size(A,1)
Ae=A(idx,:);
for jj = i:N^2
Ae1=circshift(Ae,[0 -jj]);
A(i,:)=Ae1;
end
end

답변 (1개)

dpb
dpb 2015년 7월 31일
편집: dpb 2015년 7월 31일
Warning: air code; untested...
k=0; % row counter (or compute on fly from i,j, your choice...)
L=size(A,1);
for i = 1:N:L % over number of sets of N in A
for j = i:N
k=k+1;
if k>L,break,end % done...
A(k,:)=circshift(A(k,:),[0 -j.^N]);
end
end

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by