Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I fix this ?

조회 수: 1 (최근 30일)
Eti Rastogi
Eti Rastogi 2020년 9월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
function pool_volume = A09_poolSubfunction_erastogi(surface_r, bottom_r, depth_shallow, depth_deep)
if (surface_r<0||bottom_r<0||depth_shallow<0||depth_deep<0) % calculation limitations
fprintf('Invalid input \n')
return
end
%calculating total volume of the pool
part_1= (2*pi*surface_r*depth_shallow);
part_2= (pi*(depth_deep-depth_shallow)*((surface_r)^2+(surface_r*bottom_r)+(bottom_r)^2)/3);
total_volume = (part_1+part_2)*7.48052; % total volume and conversion from feet^3 to gallons
fprintf(' The volume of the pool is % gallons \n',total_volume)
end
%Output argument "pool_volume" (and maybe others) not assigned during call to "A09_poolSubfunction_erastogi".
%this is an error im seeing while i run it
  댓글 수: 1
per isakson
per isakson 2020년 9월 28일
Rename total_volume to pool_volume ;(

답변 (2개)

madhan ravi
madhan ravi 2020년 9월 28일
function total_volume = A09_poolSubfunction_erastogi(surface_r, bottom_r, depth_shallow, depth_deep)

Steven Lord
Steven Lord 2020년 9월 28일
In addition to the output argument renaming others have suggested, as written you need to assign something to the output argument in the case where your function was called with invalid input. Otherwise you'll receive this same error in that case. Often NaN is used as an indicator that something went wrong.
Alternately I would probably throw an error (or maybe replace that if statement with four assert statements, if I wanted to throw more specific error messages like "surface_r must be nonnegative") instead of using fprintf and return.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by