Error in for loop

2 views (last 30 days)
Corey Bullard
Corey Bullard on 16 Apr 2012
I am learning MATLAB, and am having a problem with the following program. The error is in the for loop. I am unfamiliar with MATLAB errors, but it shows a gray circle with a green arrow pointing at line #39. Line 39 is the end statement that ends my if else (as opposed to the end that ends my for loop). Thanks for taking a look. I know I have a few output errors, and the formatting needs some work, I am just trying to fix this before moving on. I will also be plotting x vs y later. EDIT: When I hover over the gray circle I see a tooltip that says "Save file to synchronize breakpoints. Line 39. Status: Enabled"
clear all;
close all;
clc;
conversion = 12;
num_points = 20;
truck_lbs = 97000;
yield_str = 15000;
omega = 105.0;
modulus = 30000000;
x = 0.0;
disp('BEET TRUCK BRIDGE SAFETY');
disp('-------------------------------------------');
length_ft = input('Enter the length of the bridge (ft): ');
num_beams = input('Number of I-Beams: ');
h_beam = input('I-Beam height (in): ');
i_beam = input('Moment of inertia for one I-Beam (in^4): ');
i_bridge = i_beam*num_beams;
length_in = length_ft*conversion;
max_inertia = (truck_lbs + omega * length_in) * 0.25 * length_in;
c = h_beam * 0.5;
max_stress = max_inertia * c / i_bridge;
disp(' RESULTS\n');
disp('---------------------------------------------');
x_step = length_in / (num_points - 1.0);
disp(' Position on Bridge (in) Deflection in the Bridge (in)');
for i = 0:1.0:num_points
if x <= (length_in / 2.0)
y = x/(12*modulus*i_bridge)*( truck_lbs*(3*length_in^2*0.25-x^2)+omega*0.5*(length_in^3-2*length_in*x^2+x^3 ));
else
y = (length_in-x)/(12*modulus*i_bridge)*( truck_lbs*(3*length_in^2*0.25-(length_in-x)^2)+omega*0.5*(length_in^3-2*length_in*(length_in-x)^2+(length_in-x)^3 ));
end
disp([' ' num2str(x) ' ' num2str(y)]);
x = x + x_step;
end
disp([' Maximum Stress (psi): ' num2str(max_stress) ]);
if max_stress < yield_str
disp('Permanent damage will occur if truck crosses the bridge');
elseif max_stress > (0.5 * yield_str)
disp('Load is more than twice the safety limit');
elseif max_stress > (0.25 * yield_str)
disp('Load exceeds the safety limit');
end

Accepted Answer

Jan
Jan on 16 Apr 2012
The gray circle means, that there is a breakpoint in the line, but the file has not been saved after the last changes. After saving the file in the editor, the circle gets red. Then the execution stops in this line and you can inspect the values of the variables for debugging.
Please save the file and run it again. Otherwise even you cannot see, what's going on. If you still get an error, post the complete message here.
  1 Comment
Corey Bullard
Corey Bullard on 16 Apr 2012
Thanks a lot.
That got it!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!