Few questions in matlab assignment
조회 수: 3 (최근 30일)
이전 댓글 표시
I am sorry to bother that I am a rookie in using matlab. I can't even run the function. What should be fixed? Please give a help.
Write a MATLAB function named “cone” to accept inputs r and h, and return output V, where r, h, and V are respectively the radius, height, and volume of a cone.
function[V] = cone ( r, h )
cone=(1/3)*h*pi*(r^2);
end.
The second question is:
Write a MATLABscriptto generate data and plot the function y = 1/xas shown below. The plot is in greencolourwith diamondmarkers.
but i can only get this graph by this script:
x=linspace(-10,10,20)
y=1./x;
plot(x,y,'gd')
ylim([-1 1])
댓글 수: 0
답변 (1개)
Rik
2019년 12월 1일
If you paste your code in the Matlab editor you will see two mlint warnings and one error.
The first warning is that V is not defined in your function, the second warning is that the variable cone is unused. You should not use the name of the function as a variable, so if you replace cone by V that should solve your issue.
The error can be solved by removing the point after end.
function V = cone ( r, h )
V=(1/3)*h*pi*(r^2);
end.
As for your second question: your code should result in the upper image. The file name suggests that you are using Octave instead of Matlab. Because this is a Matlab forum, usually only questions will be answered where the issue can be reproduced in Matlab.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!