Can't use a second function inside the main one
古いコメントを表示
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!
採用された回答
その他の回答 (1 件)
madhan ravi
2018 年 11 月 14 日
編集済み: madhan ravi
2018 年 11 月 14 日
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);
カテゴリ
ヘルプ センター および File Exchange で Language Support についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!