Create a function to find the product of three numbers, I am trying to use random numbers but an error keeps coming up
조회 수: 2 (최근 30일)
이전 댓글 표시
This is my code i was testing:
function out = rand_Prod (in_a,in_b_,in_c)
in_a = rand()
in_b = rand()
in_c = rand()
rand_Prod = in_a*in_b*in_c
out = rand_Prod);
end
Then this is the error coming up
function out = rand_Prod (in_a,in_b_,in_c)
↑
Error: Function definitions are
not permitted in this context.
댓글 수: 2
Jan
2022년 11월 10일
This sounds like a homework question. Without mentioning any details and posting in in form of a command, you will not get a solution from this forum. Please solve your homework by your own.
Steven Lord
2022년 11월 10일
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
답변 (1개)
Jan
2022년 11월 10일
편집: Jan
2022년 11월 10일
Where did you create this function? This cannot happen in the command window. Open a file using the editor, create the function there and save it as M-file in a folder, which belongs to the Matlab path.
Steven has suggested the Onramp tutorial already. You find such explanations there also.
A note: Defining 3 inputs is not useful, if you overwrite them directly. So either use the inputs, or create the variables internally.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!