필터 지우기
필터 지우기

In an assignment A(I) = B, the number of elements in B and I must be the same.

조회 수: 1 (최근 30일)
Ahmad Sheikh
Ahmad Sheikh 2015년 10월 29일
답변: Thorsten 2015년 10월 29일
why is this giving an error...!
A1=[2 1];
>> for i=1:2;
A(k)=[-1 1];
A(k+1)=A1+A(k);
end
  댓글 수: 1
Al Capwn
Al Capwn 2015년 10월 29일
편집: Al Capwn 2015년 10월 29일
because A1+A(k) has dimensions 1x2 where as A(k+1) has dimensions 1x1.
A1+A(k)
is interpreted as
[A1(1)+A(k) A1(2)+A(k)].

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

답변 (2개)

Thorsten
Thorsten 2015년 10월 29일
You cannot assign a 1x2 matrix [-1 1] to a single element A(k) of a matrix.
It is not clear to me what you want to achieve with these lines. Note that your loop uses i, but i is never used in the loop.

Eng. Fredius Magige
Eng. Fredius Magige 2015년 10월 29일
A1=[]; >> for i=1:2; i=i A1(1,1)=i.*-1 A1(1,2)=1 %k==i, you mean that A1=[A1; []] % or you mean this A1' end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by