Error using horzcat Dimensions of arrays being concatenated are not consistent.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Star Strider
le 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 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!