MATLAB: Double precision changes to complex double after calculation

complexdoubleprecision

Hi everyone,
I have a matrix with very simple data in double precision but after doing a calculation (listed below) some of the numbers, not all, change to complex numbers. Even the timestamp which is not used in the calculation changes to complex. The data that changes appears to be the same as the data that doesn't change.
Any ideas?
for i = 1:length(ws);
if L(i,1) >= -500 && L(i,1) <= -12
wsstd_uns(i,1) = timestamp(i,1);
wsstd_uns(i,2) = fric(i,1).*(0.35*((-(BLH(i,1)./(vK.*L(i,1)))).^(2/3)) + (2 -(10./BLH(i,1)))).^(1/2);
wsstd_uns(i,3:5) = [ws(i,1),wgst(i,1),(wgst(i,1)-ws(i,1))];
elseif L(i,1) >= 0 && L(i,1) <= 500
wsstd_s(i,1) = timestamp(i,1);
wsstd_s(i,2) = 2.*fric(i,1).*((1 -(10./BLH(i,1))).^(1/2));
wsstd_s(i,3:5) = [ws(i,1),wgst(i,1),(wgst(i,1)-ws(i,1))];
end
end

Best Answer

Theory one: You use i as a variable. As this is a "reserved word" for complex calculations, there may be an unexpected effect.
Theory two: One of your functions or variables shadows the real MATLAB command and does something unexpected. Like you would assign plot=1 the then try to use the plot command.