Info

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

Function error in if function

조회 수: 1 (최근 30일)
Christos Papagrigoriou
Christos Papagrigoriou 2020년 6월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
%%file y.m
% Define the function
function [ y ] = x( n )
if n < 0 | n >= 10
y = 0;
else
y = 5;
end
end
it turns back with Error in y (line 4)
if n < 0 | n >= 10
this is literally copied by my lecturers instructuons.
  댓글 수: 1
Christos Papagrigoriou
Christos Papagrigoriou 2020년 6월 18일
it says not enough input arguments. cheers

답변 (1개)

Steven Lord
Steven Lord 2020년 6월 18일
If you call your function like this:
y = x()
what value should MATLAB use in the if statement condition where it tries to validate the value of n?
if n < 0 | n >= 10
You need to tell the x function what n is, like:
y = x(5)
  댓글 수: 2
Christos Papagrigoriou
Christos Papagrigoriou 2020년 6월 18일
what if I wanna introduce n as a vector like n = -15:18;?
Christos Papagrigoriou
Christos Papagrigoriou 2020년 6월 18일
Is that related to the not enough input arguments error? Kind regards

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

Community Treasure Hunt

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

Start Hunting!

Translated by