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