To implement your usecase, you can use nested loops to iterate over the t and y values and plot a line segment at each point.
Adding a sample code snippet below:
% Define the grid parameters
tspan = [0 1]; % Range of t values
yspan = [0 1]; % Range of y values
gridStep = 0.1; % Step size
% Define the function f(t, y)
odefun = @(t, y) t + y;
% Create arrays of t and y values
t = tspan(1):gridStep:tspan(2);
y = yspan(1):gridStep:yspan(2);
% Plot the lines of slope f(t, y)
hold on
for i = 1:length(t)
for j = 1:length(y)
slope = odefun(t(i), y(j));
line([t(i)-gridStep/2 t(i)+gridStep/2], [y(j)-gridStep/2*slope y(j)+gridStep/2*slope]);
end
end
hold off
% Set axis limits
xlim(tspan);
ylim(yspan);
% Add labels and title
xlabel('t');
ylabel('y');