circshift() one number ,in each iteration?

can I am do shifting the number A(2,1) of matrix (A) ,one times in each iteration,('iter=0' ,iter=iter+1)? how can do that?
A=[1 2 3;4 5 6;7 8 9]
% Shift A(2,1)
for k=1:size(A,2)-1
A(2,:)=circshift(A(2,:),[0 1])
end

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 6일
That's what the code is doing
Image Analyst
Image Analyst 2013년 10월 6일
It shifts the entire second row one element at each iteration of the loop. Is that not what you wanted? Did you want to shift only the (2,1) element and not all of the elements in the second row? Either way, why? Seems like a funny thing to do unless it's homework or something. But it can't be homework because you would have tagged it as homework, so why do you want to do this?

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 6일

0 개 추천

Maybe you want to save all the results
clear
A=[1 2 3;4 5 6;7 8 9]
% Shift A(2,1)
for k=1:size(A,2)-1
A(2,:)=circshift(A(2,:),[0 1])
out{k}=A
end
celldisp(out)

댓글 수: 6

Mary Jon
Mary Jon 2013년 10월 6일
편집: Mary Jon 2013년 10월 6일
I am have this error!!!
Undefined function or variable "out".
Error in ==> sumaei at 26 celldisp(out)
(by using matlab R14)
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 6일
copy and paste the code, there is no error
Mary Jon
Mary Jon 2013년 10월 6일
편집: Azzi Abdelmalek 2013년 10월 6일
yes, there is no error, but when I am applied on my code Iam have error!!!
my code is
d=2:1:33;
E_0=(1/(36*pi))*1e-9;
E_r=1;
E=E_0*E_r*ones(111,34);
E(2:5,d)=10;
E(7:17,2:33)=4;
E(20,1)=100; % Shift E(20,1)=100
for k=1:size(E,20)-1
E(20,:)=circshift(E(20,:),[0 1])
out{k}=E
end
celldisp(out)
Image Analyst
Image Analyst 2013년 10월 6일
E doesn't have a 20th dimension so size(E,20)-1 = 0-1 = -1 which means your loop never gets entered. So when it comes time to do celldisp(), there is no out at all to display.
Mary Jon
Mary Jon 2013년 10월 6일
isnt it? that mean E(20,1) at row number 20,column number 1,
I am want shifting it (2:33),with save all the result not last result only
Image Analyst
Image Analyst 2013년 10월 6일
편집: Image Analyst 2013년 10월 6일
size(array, n) means the length of array in the nth dimension. It DOES NOT mean array(n) which is the value of the array at index n. They're totally different things. By the way, you never answered my question in the comment at the very top.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 10월 6일

댓글:

2013년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by