How to solve: Error: Output argument "variable_name" (and maybe others) not assigned during call to "function_name" ?

15 ビュー (過去 30 日間)
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

採用された回答

Adam Danz
Adam Danz 2019 年 8 月 31 日
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 件のコメント
Said Bolluk
Said Bolluk 2019 年 9 月 3 日
Actually I mentioned that I updated the code. Putting curvature out of the I loop obviously will return the value, but my latest question is not related to returning curvature. The function still doesn't get in the I loop while there is no way to break unless if statement is satisfied.
Adam Danz
Adam Danz 2019 年 9 月 4 日
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)

サインインしてコメントする。

その他の回答 (2 件)

R.G.
R.G. 2019 年 8 月 31 日
編集済み: R.G. 2019 年 8 月 31 日
Hello. You have a wrong values in for loop:
for i = 1:1:(length(lis) - 1)
The variable lis is empty because in line
lis = linspace(0, c, c * 10)
the variable 'c' equals 0, so you sequence is from 0 to 0 with 0 values :)
  3 件のコメント
R.G.
R.G. 2019 年 8 月 31 日
編集済み: R.G. 2019 年 8 月 31 日
Just try it. Change following lines:
  • for c = 0:5e-3:h TO for c = 1e-3:5e-3:h
  • lis = linspace(0, c, c * 10) TO lis = linspace(0, c, 10)
Said Bolluk
Said Bolluk 2019 年 8 月 31 日
Okay. Your point is correct but I guess MATLAP skips that numerical error and gives the correct results. Anyways, thank you for helping on this one.

サインインしてコメントする。


Said Bolluk
Said Bolluk 2019 年 9 月 4 日
I appreciate your effort and thank you. Actually the duration of the code was my another problem. Matlab suggested me to initiate the moment and curvature arrays with zero arrays so there will be a faster performance as they gets result over each iteration. But I couldn't see any difference. There needed to be higher amount of iteration to get more consistent results. I'll try to explain briefly the code so you might suggest some solutions for making it faster. The axial_matlab determines a c value which is the neutral axis depth of the section where the summation of compression forces(Fc coming from i loop) and tension forces(Fs) is equal to zero. To calculate the compression force coming from the contribution of concrete (Fc), I separated the area above the neutral axis c and calculated the cross sectional area and strain value for that specific area respectively. That's what the i loop does simply. And in the main function moment_curvarute, I calculate the c values for each strain value ec_top. Calculating the c value has the higher priority so the number of iteration must go to a higher level. I hope it makes sense to you.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by