I have fixed your script, it didn't have a time reference.
MATLAB functions conv and conv2 do not have time reference. It's done on purpose to avoid conv and conv2 having to handle time resolution problems.
clear all;close all
f1 = @(P,t0,v) rectangularPulse(-t0-P/2,-t0+P/2,v);
t = -5:dt:5;
this is a simplified version of another convolution function WITH time reference that assumes the time vectors of y1 and y2 are equal in amount and start stop moments, your vector t for y1 y2 is just that, a good reference to then generate nt1 and nt2.
Note that I have used the variable dt right on the definition of t.
The key point for this simplified version to work is to amplify to so that you get the numerals
nt1 and nt2 have to be vector indices.
Also, I learnt signal processing with negative time delays meaning shift scope left and positive time delays meaning shift scope right. If you want it reversed the function has to be redefined
f1 = @(P,t0,v) rectangularPulse(t0-P/2,t0+P/2,v);
Appreciating time and attention, thanks in advance
To any other reader, please if you find this answer of any help solving your question, please click on the thumbs-up vote link, thanks too