Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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 visualizzazione (ultimi 30 giorni)
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)

Risposte (1)

James Tursa
James Tursa il 6 Ott 2016
Modificato: James Tursa il 6 Ott 2016
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 Commenti
Emre Tunc
Emre Tunc il 6 Ott 2016
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 il 11 Ott 2016
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);

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by