MATLAB: How to solve: Error: Output argument “variable_name” (and maybe others) not assigned during call to “function_name”

assignedoutput

I try to get the moment-curvature diagram for the pre-stressed concrete beam section. However, I see this error when I run the code:
function [] = moment_curvature_matlab()
curvature_list = zeros(1, 1000000);
moment_list = zeros(1, 1000000);
ecu = 0.0038;
for ec_top = 0:5e-4:ecu
[curvature, moment] = axis_matlab(ec_top);
curvature_list = [curvature_list, curvature];
moment_list = [moment_list, moment];
end
plot(curvature_list, moment_list);
end
%%%%%%%
function [curvature, moment] = axis_matlab(ec_top)
h = 910;
d = 795;
ht = 180;
b = 450;
bw = 140;
As = 1700;
%fp = 1100;
fcu = 50;
Ec = 12680 + 460 * fcu;
Es = 200 * 1e3;
ec0 = 2 * fcu / Ec;
%ecu = 0.0038;
for c = 0:5e-3:h
fs = Es * (c - d) * ec_top / c;
Fs = fs * As * 1e-3;
lis = linspace(0, c, c * 10);
total_force = Fs;
total_moment = Fs * (d - h / 2) * 1e-3 * -1;
for i = 1:1:(length(lis) - 1)
if lis(i) <= ht && lis(i) >= h - ht
b_i = b;
else
b_i = bw;
end
h_i = lis(i + 1) - lis(i);
y_i = (h / 2) - lis(i) + (h_i / 2);
e_i = c - lis(i) + (h_i / 2);
ec_i = ec_top * (c - e_i) / c;
fc_i = fcu * ((2 * ec_i / ec0) - (ec_i / ec0) ^ 2);
Fc_i = fc_i * h_i * b_i * 1e-3;
M_i = Fc_i * y_i * 1e-3;
total_force = total_force + Fc_i;
moment = total_moment + M_i;
curvature = ec_top / c;
end
if -1 < total_force && total_force < 1
break;
end
end
end
%%%%%%
>> moment_curvature_matlab
Output argument "curvature" (and maybe others) not assigned during call to "moment_curvature_matlab>axis_matlab".
Error in moment_curvature_matlab

Best Answer

If you set a break point just before your i-loop and step through the code, you'll notice that 1) the code never enters the i-loop and 2) the c-loop only has 2 iterations until the condition at the end is met and the 'break' ends the function.
Just as the error message indicates, "curvature" is never assigned because the code never gets to that line.
I suggest learning how to debug using the 2 links above. Step through your code, line by line and determine if each line is behaving the way you expect it to.