MATLAB Answers

0

It keeps returning "Output argument "def" (and maybe others) not assigned during call to "shearbend"." but I'm not sure why. I need it to return 4 vectors but I'm not sure why it isn't working.

Asked by Tyler Seifert on 2 Apr 2019
Latest activity Answered by Geoff Hayes
on 3 Apr 2019
I need to return 4 vectors but it keeps saying the outputs aren't defined. Any clue why?
function [def, shf, bend, x] = shearbend(L, E, i, type, varargin)
if type == 1
iter = 0;
c = 0;
for j = 1 : length(varargin)/2
a = varargin(2 + iter);
P = varargin(1 + iter);
b = L - a;
def(a) = (P*a^2*b^2)/(3*E*i*L);
R1 = (P*b)/L;
R2 = (P*a)/L;
Ma = (P*a*b)/L;
Mslope = (-Ma)/b;
iter = iter + 2;
for x = linspace(0, L)
c = c + 1;
if x < a
def(c, j) = ((P*b*x)/(6*E*i*L))*(L^2-b^2-x^2);
shf(c, j) = R1;
bend(c, j) = (P*b*x)/L;
elseif x > a
def(c, j) = ((P*a*(L-x))/(6*E*i*L))*(2*L*x-x^2-a^2);
shf(c, j) = R1-P;
bend(c, j) = Ma+Mslope*(x-a);
end
x(c) = x;
end
end
for r = 1 : c
valdef = 0;
valshf = 0;
valbend = 0;
for col = 1 : j
def(r,col) = valdef + def(r, col);
valdef = def(r);
shf(r,col) = valshf + shf(r, col);
valshf = shf(r);
bend(r,col) = valbend + bend(r, col);
valbend = bend(r);
end
end
end
end

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Geoff Hayes
on 3 Apr 2019

Tyler - what are the inputs that you are passing to this function? Some or all of the output parameters will only be set if the condition of the if statement is true (so type == 1) and if the body of the for loop is evaluated. To avoid this error, you should initialize these output parameters to something. For example,
function [def, shf, bend, x] = shearbend(L, E, i, type, varargin)
def = [];
shf = [];
bend = [];
x = [];
if type == 1
end
end
That being said, there still might be some issues with your code. For example, the inner for loop that iterates over x...which is one of your output parameters
for x = linspace(0, L)
c = c + 1;
if x < a
def(c, j) = ((P*b*x)/(6*E*i*L))*(L^2-b^2-x^2);
shf(c, j) = R1;
bend(c, j) = (P*b*x)/L;
elseif x > a
def(c, j) = ((P*a*(L-x))/(6*E*i*L))*(2*L*x-x^2-a^2);
shf(c, j) = R1-P;
bend(c, j) = Ma+Mslope*(x-a);
end
x(c) = x;
end
I don't understand how you can use x as your loop iterating variable and as an array. Is this intentional? Should the x in x(c) = x be named something else?
Also, you are updating the bend matrix in the above code only to update (overwrite?) it later in the second double for loop. Is this intentional as well?
Finally, does
for j = 1 : length(varargin)/2
a = varargin(2 + iter);
P = varargin(1 + iter);
b = L - a;
def(a) = (P*a^2*b^2)/(3*E*i*L);
make sense given your inputs? What are the a indices for your def output parameter? Please review your code to convince yourself that it is doing what you intend it to be doing.

  0 Comments

Sign in to comment.