MATLAB Answers

0

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

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

답변 수: 3

Adam Danz 님의 답변 31 Aug 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

표시 이전 댓글 수: 3
"I performed what you expalined above and the i loop never works as you said"
That's because the file you attached in the comment above differs from what you gave us previously. The file attached to your question and copy-pasted to your question is not the same code as what you just attached.
The new version no longer has the error because "curvature" is now assigned outside of the i-loop so if the code never enters the i-loop, the curvature variable still gets assigned.
Looks like that problem is solved.
Lesson learned: if you're working with a different code than us volunteers, there's no way we can really help solve the problem.
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.
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)

로그인 to comment.


R.G. 님의 답변 31 Aug 2019
R.G. 님이 편집함. 31 Aug 2019

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

Hello. Thank you for your reply. Are you sure about it? You see, the loop starts with zero so the lis array will be zero. However, it gets extended with the numbers related to "c" value. Also, the code "axis_matlab(ec_top)" runs perfectly by itself.
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)
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.

로그인 to comment.


Said Bolluk 님의 답변 4 Sep 2019

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.

  댓글 수: 0

로그인 to comment.



Translated by