Output argument "rmax" (and maybe others) not assigned during call to "bestdesign".
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Output argument "rmax" (and maybe others) not assigned during call to "bestdesign".
M-File
function [max,rmax,hmax]=bestdesign(L,W,H,start,stop)
r=start;
max=0;
if r<=stop
num = InsectContainers(L,W,H,r);
if num > max
max=num;
rmax=r;
else
r=r+0.0001;
end
else hmax=1000/(pi*rmax^2);
end
Can someone tell me why this isn't working please?
Here is the code for InsectContainers.m if it helps
function numContainer = InsectContainers(L,W,H,r)
V = 1000;
h = V/(pi*(r^2));
Stacks = fix(H/h);
Rows = fix(L/(2*r));
Num = fix(W/(2*r));
numContainer = Stacks*Rows*Num;
end
0 commentaires
Réponses (2)
Star Strider
le 6 Oct 2016
The easiest way to correct that is to assign all your return variables as something, then replace them as necessary in the code:
function [max,rmax,hmax]=bestdesign(L,W,H,start,stop)
[max,rmax,hmax] = deal(NaN, NaN, NaN); % <— ADD THIS LINE
r=start;
max=0;
if r<=stop
num = InsectContainers(L,W,H,r);
if num > max
max=num;
rmax=r;
else
r=r+0.0001;
end
else hmax=1000/(pi*rmax^2);
end
0 commentaires
Marc Jakobi
le 6 Oct 2016
You should initialize rmax and hmax at the beginning of your function. If r is greater than stop, hmax is never defined and if num is smaller than or equal to max, rmax is never defined.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!