Info

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

When I try to run the following line of code, I get the error message "Not enough input arguments. Error in Un2 (line 6) if (R<=0)||(H<=0)" Although I understand the content of the error message, I cannot determine what is wrong with my syntax.

조회 수: 1 (최근 30일)
Please help me for the codes that calculates and returns the volume and cross-sectional area of a cylinder based on the radius and height?
function A=sect_area_cylinder(R,H,alpha)
%Cylinder of radius R and height H,
%its base-circle center coincide with the point (0,0,0).
%The intersecting plane is supposed to rotate around the
%line (x=0,y=H/2) with angle ALPHA (in degrees)
if (R<=0)||(H<=0)
error('Input positive R,H');
end
if alpha==0
%the cross-section is a circle
A=R^2*pi;
elseif alpha==90
%the cross section is a rectangle
A=2*R*H;
elseif (0<alpha)&&(alpha<90)
%the cross section is an ellipse
%of short radius R and long radius R/cos(alpha)
A=pi*R*R*cos(alpha*pi/180);
else
disp('alpha in [0,90]');
end
it gives me error all time :( any idea what the wrongs are?
Not enough input arguments.
Error in Un2 (line 6) if (R<=0)||(H<=0)

답변 (1개)

James Tursa
James Tursa 2016년 10월 6일
편집: James Tursa 2016년 10월 6일
It means that R and/or H were not passed in as arguments to the function. Did you just push the green triangle "Run" button to run the code from the editor? That will run the code without any input arguments and generate the error. You need to call the function (e.g. from the command line) with input arguments.
(Although this is a bit confusing because the error message you show refers to a function called Un2, whereas the code you show has a function named sect_area_cylinder ... maybe this is in a file called Un2.m?)
  댓글 수: 2
Emre Tunc
Emre Tunc 2016년 10월 6일
yes you are right I have input arguments too for sectional area of the cylinder and it works well. But I have to put volume of the cylinder too how can I put mutliple outputs now?
James Tursa
James Tursa 2016년 10월 11일
Modify your function code as follows:
function [A,V]=sect_area_cylinder(R,H,alpha)
%
% Your original area code goes here
%
% Then add your new volume code here
V = whatever;
Then when you call the function, store the result into two variables. E.g.,
[Aresult,Vresult] = sect_area_cylinder(R,H,alpha);

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by