In an assignment A(I) = B, the number of elements in B and I must be the same. this is the error i am getting
조회 수: 10 (최근 30일)
이전 댓글 표시
hi i am trying to assign few values like this "for k=1:1:12 rh(k)=[200 300 400 400 900 1300 1350 1300 1000 700 650 350]; end"
the error i am getting is In an assignment A(I) = B, the number of elements in B and I must be the same. i have to assign rh(1)=200, rh(2)= 300 and so on till rh(12)=350. can anyone please help me?
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 10월 25일
You don't need a for loop for that
rh=[200 300 400 400 900 1300 1350 1300 1000 700 650 350];
댓글 수: 7
추가 답변 (1개)
Zack Peters
2013년 10월 24일
Hi Trilochan,
MATLAB is a powerful resource for matrix indexing operations. Rather than loop through and assign each element of the array to each element of variable 'rh' why don't you try the following:
rh(1:12) = [200 300 400 400 900 1300 1350 1300 1000 700 650 350];
or alternatively if variable 'rh' only has 12 elements, you can get rid of the (1:12) indexing and instead simply use:
rh = [200 300 400 400 900 1300 1350 1300 1000 700 650 350];
~Zack
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!