Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuestas (1)
James Tursa
el 6 de Oct. de 2016
Editada: James Tursa
el 6 de Oct. de 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 comentarios
James Tursa
el 11 de Oct. de 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);
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!