Not enough input arguements

Hello i get the error " Not enough input arguments"
I have a function with 2 inputs. A variable called anz and a matrix (8x10). Matrix is a exported excel.
pls help
excelDatei = ' test.xlsx'
tabelle= 'tabelle 1'
zellBereich = 'A1:J9'
anz=height(matrix)
matrix=readtable(excelDatei, 'Sheet', tabelle, 'Range', zellBereich);
testfct(anz, matrix)
function [result 1, result 2, result3] = testfct (anz, matrix)
for i : anz
element=matrix.ID(i)
end

6 件のコメント

Stephen23
Stephen23 2024 年 3 月 15 日
編集済み: Stephen23 2024 年 3 月 15 日
After fixing a few syntactical bugs the code runs without error:
n = 5;
s.ID = [11,22,33,44,55];
testfct(n,s)
element = 11
element = 22
element = 33
element = 44
element = 55
function [result1, result2, result3] = testfct(anz, matrix)
for k = 1:anz
element=matrix.ID(k)
end
end
Mehdi Ansarey
Mehdi Ansarey 2024 年 3 月 15 日
send more complet code. its for loop is errorneous. maight be sth like for i=?:anz
max muster
max muster 2024 年 3 月 15 日
stephen but whats wrong with my code. I get this error not on every compile but sometimes
Torsten
Torsten 2024 年 3 月 15 日
E.g. the line
for i : anz
will produce an error, but usually each time you run the code, not only sometimes.
Dyuman Joshi
Dyuman Joshi 2024 年 3 月 15 日
編集済み: Dyuman Joshi 2024 年 3 月 15 日
"but whats wrong with my code"
As mentioned, there is a syntax error in the for loop. See - for; also, compare the for loop section in your code and Stephen's code.
You have specified 3 outputs for the function, yet the code does not define any of them.
It's not clear what you want to do. If you want to get all values of ID column/variable from table matrix, you can directly assign it like this -
element = matrix.ID;
If that is not what you want to do, please specify.
Additionally, use a semi-colon to suppress the outcome of the lines.
Stephen23
Stephen23 2024 年 3 月 15 日
"I get this error not on every compile but sometimes"
Please show us the complete error message. This means all of the red text.

サインインしてコメントする。

回答 (1 件)

VBBV
VBBV 2024 年 3 月 15 日
編集済み: VBBV 2024 年 3 月 15 日

0 投票

anz=height(matrix)

Put this line after readtable function where you read the data from Excel. The input to the function height is matrix and the output to the readtable function

4 件のコメント

max muster
max muster 2024 年 3 月 15 日
I did. No change
max muster
max muster 2024 年 3 月 15 日
Could the mistake be generally that i made my function with New --> new script instead of new function (is m file anyways) ?
Dyuman Joshi
Dyuman Joshi 2024 年 3 月 15 日
編集済み: Dyuman Joshi 2024 年 3 月 15 日
Unless you are using R2016a or older versions, that will not be a problem.
Functions in a script are allowed with the restriction that they are defined at the end (bottom) of the script, which you have done.
You should check the comments above.
VBBV
VBBV 2024 年 3 月 16 日
編集済み: VBBV 2024 年 3 月 16 日
@max muster, As mentioned by others in comments to your question, there are syntax problems related to for loop inside the function. Generally the syntax for loop is
for i = 1:anz
element(i)=matrix.ID(i)
end
element % function outputs

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2024 年 3 月 15 日

編集済み:

2024 年 3 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by