Error using horzcat Dimensions of arrays being concatenated are not consistent.
조회 수: 2 (최근 30일)
이전 댓글 표시
Not sure why I'm recieving this error for this code:
h= 0.1;
t0= 0;
y1=-0.25;
tEnd=2;
T=[t0:h:tEnd];
N=20;
Y=zeros(N+1,1);
%solving with Taylor series
for i=1:N
Y1= sin(4*T);
Y2= 4*cos(4*T);
Y3= -16*sin(4*T);
Y4= -64*cos(4*T);
Y(i+1)= Y(i) + Y1(i)*h + (Y2(i)/2)*h^2 + (Y3(i)/6)*h^3 + (Y4(i)/24)*h^4;
end
>> [T,Y]
댓글 수: 0
답변 (1개)
Star Strider
2020년 1월 9일
The reason is that ‘T’ is a (1x21) row vector, and ‘Y’ is a (21x1) column vector.
The (:) subscript convention forces ‘T’ to become a column vector here, so the concatenation works:
Result = [T(:),Y]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!