Error in variables being unset and unused
4 ビュー (過去 30 日間)
古いコメントを表示
My issue stems from the subfunctions, I keep getting the error that the variable endarea is 'unset', and calcend is 'unused' and the same with every following function. This is the error message that shows up in the commmand line when run
>> geo(3,5)
calcend =
28.2743
Output argument "endarea" (and maybe others) not assigned
during call to "geo>calcend".
Error in geo (line 2)
enda = calcend(radius);
As you can see the first value is calculated and is correct, but then the error message. From here I have no clue what is happening or how to get the code running. the correct values output should be
End area = 28.27
Perimeter = 18.85
Side area = 94.25
Total area = 150.80
Volume = 141.37
function geo(radius, height)
enda = calcend(radius);
per = perimeter(radius);
sida = areaofside(radius, height);
tota = totalarea(radius, height);
vol = volume(radius, height);
printdata(enda, per, sida, tota, vol)
end
function endarea = calcend(rad)
calcend = pi*rad^2
end
function perimeterofbase = perimeter(radi)
perimeter = 2*pi*radi;
end
function sidarea = areaofside(radiu,h)
areaofside = 2*pi*radiu*h;
end
function areatotal = totalarea(radiuss,hi)
totalarea = 2*pi*radiuss^2 + 2*pi*radiuss*hi;
end
function volum = volume(radiusss, hig)
volume = pi*radiusss^2*hig;
end
function printdata(enda1,per1,sida1,tota1,vol1)
fprintf('end area %6.2f\n', enda1);
fprintf('perimeter %6.2f\n', per1);
fprintf('side area %6.2f\n', sida1);
fprintf('total area %6.2f\n', tota1);
fprintf('volume %6.2f\n', vol1);
end
0 件のコメント
採用された回答
Steven Lord
2019 年 2 月 27 日
function endarea = calcend(rad)
calcend = pi*rad^2
end
Your function is declared to return the contents of the variable named endarea in its workspace to its caller as the first (and only) output. Do you ever define a variable named endarea in the workspace of this function? If not, what should this function actually return to its caller?
Since the answers to those questions are "No" and "I don't know" respectively, MATLAB tells you "This function doesn't know what to return to its caller" only it words it slightly differently.
The solution is to define the variable named endarea inside this function. This solution also applies to the rest of your functions that declare that they return something to their caller, though with different names (perimeterofbase, sidarea, areatotal, and volum.)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!