How to solve: Error: Output argument "variable_name" (and maybe others) not assigned during call to "function_name" ?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Said Bolluk
el 31 de Ag. de 2019
Respondida: Said Bolluk
el 4 de Sept. de 2019
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
1 comentario
Respuesta aceptada
Adam Danz
el 31 de Ag. de 2019
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.
6 comentarios
Adam Danz
el 4 de Sept. de 2019
The function does enter the i-loop.
I added a waitbar to your c-loop so I can monitor progress (see code below). Your c-loop has up to 182000 iteration and within each iteration you have a nested i-loop with a variable amount of iterations. So this code could take a very long time.
Note that I haven't tried to understand the code so I can't make recommendations on a faster solution. As is often the case, the best solution is to practice matlab debugging by putting a break at the start of your c-loop, running the code, and stepping through it line by line to understand how the iterations are progressing.
wb1 = waitbar(0,'c-loop'); % Create waitbar
for c = 1e-10:5e-3:h
% Update waitbar #1
waitbar(find(1e-10:5e-3:h == c) / numel(1e-10:5e-3:h), wb1)
Más respuestas (2)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!