MATLAB: Unable to perform assignment because the left and right sides have a different number of elements

findfor loop

Hi, I am having trouble with the second for loop in this function. I keep getting the error "Unable to perform assignment because the left and right sides have a different number of elements". It works for the first couple iterations but stops after that.
for i=1:50
theta(i) = 90 - beta(i);
end
a = theta(theta>15);
Po = 200;
for j = 1:length(a) %% this for loop not working
beta_new(j) = 90-a(j);
Pout(j) = Po*cosd(beta_new(j));
index(j) = find(beta_new(j) == beta);
end

Best Answer

90 - (90 - Something) is not necessarily equal to Something when you use floating point arithmetic. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F