MATLAB: How to get the code working when it says ‘Attempted to access y(2); index out of bounds because numel(y)=1.’

matrix manipulationodeode45ordinary differential equationsvector

I'm trying to make my code work but it keeps on saying 'Attempted to access y(2); index out of bounds because numel(y)=1.' and I don't know how to make it work. Any solution to this?
The code is as follows:
function F = matrix_assessment(T,y)
t = 0.5; % This is assumed
% First ODE
F1 = 5*y(2)-y(1)+y(3);
% Second ODE
F2 = 3*y(1)-y(2)+t^2;
% Third ODE
F3 = y(3)-t*y(2);
F = [F1 ; F2 ; F3];
% Run matrix_assessment
% Script File
yinit = [0,0,0]; % Initial values for y
[T,y] = ode45('matrix_assessment',(0:0.1:1),yinit);
plot(T,y(:,1),'r', T, y(:,2),'b', T, y(:,3),'k')

Best Answer

Did you pass a vector in for y? Something like
y = [1,4,7,3]; % OK - y is more than one number.
output = matrix_assessment(T,y)
Probably not. You probably did
y = 42; % Bad - y is only one number.
F = matrix_assessment(T,y)