Hi,
You can try using Financial Toolbox present in MATLAB in order to cater to your needs.
For instance, "pvvar" function can be used to calculate the present value of varying cash flow. You can refer to the following documentation to know more about it.
Further, Financial Toolbox provides a collection of financial tools to compute cash flows and sensitivities for annuities, amortization and depreciation, present and future value, and rates of return. Kindly follow the below mentioned documentation for more information.
Alternatively, if you want to proceed through analytical approach, then you need to adjust the cash flow values iteratively until the NPV is zero. This is typically done using a numerical method such as "Newton-Raphson" method. You can check out the following sections of symbolic Math Toolbox for related examples.
You can also search through the File Exchange forum for numerical solvers such as Newton-Raphson. For instance, following is one such resource that provides a demonstration of the "Newton-Raphson" method.
I hope it will help you to resolve this problem.
Regards,
Zuber