MATLAB: Can anyone please explain this? I tried to implement this code on Matlab, but the graph is blank. I do not know what I did wrong.

plotting

Mass_A = 10; % mass in kg
Us = 0.15;
Mass_B = 0;% The range of values of Mass_B with 5kg increment
g = 9.81;
while (Mass_B <= 50)
Angle = atan((4.5+0.15*Mass_B)/(-10+Mass_B));
Mass_B = Mass_B + 5;
end
plot(Mass_B,Angle,'r')
xlabel('Mass_B (kg)');
ylabel('The angle in rad');
title('The angle in rad Vs Mass_B (kg)');

Best Answer

Loop is superfluos here , the reason for your error is you forgot to save the variables in each loop iteration (you overwrote) , to save them use a counter as index to store them in each iteration but I would completely avoid them because straight away the result can be obtained.
Mass_A = 10; % mass in kg
Us = 0.15;
Mass_B = 0:5:50;% The range of values of Mass_B with 5kg increment
g = 9.81;
% while (Mass_B <= 50)
Angle = atan((4.5+0.15.*Mass_B)./(-10+Mass_B));
% Mass_B = Mass_B + 5;
% end
plot(Mass_B,Angle,'-r*','LineWidth',2)