The ‘Pk_prev’ variable is a (2x2) matrix. You cannot assign that to a scalar array element in ‘P’.
If you preallocate ‘P’ as:
P = zeros(2,2,length(z));
and then assign it as:
your code works. You then need to plot ‘z’ as:
Plotting ‘P’ however is not possible with your current code.
You can plot it with this:
for k = 1:size(P,3)
Experiment to get the result you want.