creating matrix with iteration

조회 수: 11 (최근 30일)
Akmyrat
Akmyrat 2014년 8월 5일
댓글: Akmyrat 2014년 8월 9일
lets say I have this code: for i=1:4 sum=1+i end i want program to create a ix2 matrix (1st column values are 3) at each iteration. ex: at i=3 => A=[2 3;3 3;3 4] at i=4 => A=[2 3;3 3;3 4;3 5]

채택된 답변

Hikaru
Hikaru 2014년 8월 5일
Try this code, but you have to specify n for the number of rows.
A = zeros(n,2);
A(:,1) = 3;
for i=1:n
A(i,2) =1+i;
end
  댓글 수: 2
Akmyrat
Akmyrat 2014년 8월 5일
thanks a lot Hikaru
Akmyrat
Akmyrat 2014년 8월 9일
Hi Hikaru how are You? Can U help with this PLEASE: n=4 for i=1:n s=i if s == 3 for k =1:2 A(i,1) =s A(s+1,1)=s end else A(i,1) =s end end I want like this result: A=[1;2;3;3;4]. which if s == 3 it should be repeated 3 times in the matrix.

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

추가 답변 (1개)

Julia
Julia 2014년 8월 5일
A = zeros(i,2);
A(:,1) = 3;
A(:,2) = 2:sum;
  댓글 수: 1
Akmyrat
Akmyrat 2014년 8월 9일
Hi Julia how are You? Can U help with this PLEASE: n=4 for i=1:n s=i if s == 3 for k =1:2 A(i,1) =s A(s+1,1)=s end else A(i,1) =s end end I want like this result: A=[1;2;3;3;4]. which if s == 3 it should be repeated 3 times in the matrix.

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

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by