MATLAB: PDE Boundary Condition only returns 1 evaluation Point

boundary conditionpde

So Im trying to implement a Boundary Condition for the PDE Toolbox by
applyBoundaryCondition(model_Zeo,'Edge',3,'u',@Kanaldruck_v1,'EquationIndex',1,'Vectorized','on');
and the function
function Kanaldruck = Kanaldruck_v1 (region, state)
global p_c t_step time Kzahl j
if(isnan(state.time))
Kanaldruck = NaN;
else
if time ~= round(state.time,6,'significant')
time=round(state.time,6,'significant');
j=ceil(time*Kzahl/t_step);
if j==0
j=1;
elseif j>Kzahl
j=Kzahl;
end
end
Kanaldruck=p_c(:,j)';
end
where p_c ist a 101×18 Matrix and j is a Integer between 1 and 18. So the Kanaldruck is a 1×101 Matrix. Now i get the following error
Boundary condition function "Kanaldruck_v1" was requested to return boundary conditions at 101 points but values at 1 point(s) were returned.
I've put a breakpoint at the last line, noticing, that the error only occures after the second time i run through the function. If i dont transpose the p_c Matrix, the very same error appears after the first runtrough (which makes sense). Maybe i did unterstand the purpose of 'Vectorized''on' falsely… it would be very nice if someone could tell me if my syntax is correct, and where the error could come from.

Best Answer

i figured it out. It happens if state.time is NaN. Instead of
if(isnan(state.time))
Kanaldruck = NaN;
else
i had to pass
if(isnan(state.time))
Kanaldruck = NaN([1,length(region.x)]);
else