필터 지우기
필터 지우기

Info

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

How can I input a matrix into a matlab function?

조회 수: 1 (최근 30일)
Manuel Loeza-Orozco
Manuel Loeza-Orozco 2016년 10월 22일
마감: MATLAB Answer Bot 2021년 8월 20일
Basically I was asked to write a program that takes in a vector (in its x y z components) and check whether the length of that vector would be inside, touching or on the outside of the sphere of radius 1. If its inside or touching the rim of the sphere, then the function would output "1" if it lies on the outside it would output "0".
Here is my code
function c = inside_sphere(x,y,z)
vmag = sqrt( x^2 + y^2 + z^2);
if vmag <= 1
fprintf('1 \n');
elseif vmag > 1
fprintf('0 \n');
end
If I run the function by inputing statements like this
"inside_sphere(0.3,0.4,0.54)"

답변 (1개)

Walter Roberson
Walter Roberson 2016년 10월 22일
When they say "output" they mean the return value of the function, not displayed to the screen.

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by