Error using horzcat Dimensions of arrays being concatenated are not consistent.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 9 Jan. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!