Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Function error in if function

1 visualizzazione (ultimi 30 giorni)
Christos Papagrigoriou
Christos Papagrigoriou il 18 Giu 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
%%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 Commento
Christos Papagrigoriou
Christos Papagrigoriou il 18 Giu 2020
it says not enough input arguments. cheers

Risposte (1)

Steven Lord
Steven Lord il 18 Giu 2020
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 Commenti
Christos Papagrigoriou
Christos Papagrigoriou il 18 Giu 2020
what if I wanna introduce n as a vector like n = -15:18;?
Christos Papagrigoriou
Christos Papagrigoriou il 18 Giu 2020
Is that related to the not enough input arguments error? Kind regards

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by