Can't use a second function inside the main one
Afficher commentaires plus anciens
Hello! I've been trying to fix this for over a day now (I'm a begginner in mathlab) and I've not been able to get this piece of code to work.
Basically, i've got 2 functions. The first one asks for values and, after calling the second function, processes the values received.
This is the main function:
function [x, invert] = func(number)
x = input('insert an integer bigger than 0: ');
while x < 0 || mod(x, 1)~=0
x = input('insert again: ');
end
matri = ones(1, x);
k = 1;
while k <= x
sub;
matri = number * matri(k);
k = k + 1;
end
invert = matri(end:-1:1);
end
The second function is this:
function [number] = sub
w = input('insert a number: ');
if w > 100
number = w/3;
else
number = w/2;
end
end
And to call them, i use this script:
func;
[number] = sub;
[invert] = func(number);
disp(invert);
When I run the script, I get asked to input the values and then I get this error: "Error using func (line 15). Not enough input arguments.". I've looked many times into the code, but I can't understand whats missing.
In that specific line I'm trying to grab the number returned by the second function and store it in a matrix.
Any help is appreciated!
Réponse acceptée
Plus de réponses (1)
madhan ravi
le 14 Nov 2018
Modifié(e) : madhan ravi
le 14 Nov 2018
number = sub;
invert = func(number);
disp(invert);
your code
func; -> which needs an input here , this line was superfluos
[number] = sub;
[invert] = func(number);
disp(invert);
1 commentaire
Ruben Lourenco
le 21 Nov 2018
Catégories
En savoir plus sur Language Support dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!