how to fix "In an assignment A(I) = B, the number of elements in B and I must be the same"
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
This is the code I wrote to store values in a vector but it is not working for some reason. I have realized that I am adding vector to a scalar but I am not sure how to fix it!
CODE ======================================================================
y1 = 1;
deltT = 1;
for t1=1:1:10;
y1(t1) = y1 + t1*deltT
end
==================================================
ERROR MESSAGE
y1 =
2
y1 =
2 4
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in Untitled (line 17)
y1(t1) = y1 + t1*deltT ================================================================================
Help would me much appreciated! Thanks!
댓글 수: 0
답변 (2개)
sixwwwwww
2013년 10월 11일
You should not use same name for variable and array. You are using "y1" as variable as well as an array later in for loop. So you can do it correctly this way:
y = 1;
deltT = 1;
for t1=1:1:10
y1(t1) = y + t1*deltT
end
or in a better way
y = 1;
deltT = 1;
t1 = 1:10;
y1 = y + t1 * deltT
Good luck!
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!