How to catch 'not enough input arguments' error?

Is there any way I can catch the error 'Not enough input arguments'? For e.g. the below line in a function of my big code throws this error.
spn=spans(index) %spans is an array of 9 elements and 'index' itself is something I extract from an array
Problem: As this line is inside a function, the code stops upon getting error and I can't access the function workspace to see what was causing this. And since this error does not appear every time but mostly after a long time the code runs, it is not feasible for me to put breakpoint here and check every time by pressing continue
So is there any piece of code I can write here and put a breakpoint so that when this error comes it it pauses there for me to see the value of index or the corresponding function parameters?

 採用された回答

Chunru
Chunru 2021 年 9 月 9 日
編集済み: Chunru 2021 年 9 月 9 日

0 投票

Use try-catch:
try
spn=spans(index)
catch
whos index % show the inforamtion of the variable index
disp(index)
end

3 件のコメント

Jaya
Jaya 2021 年 9 月 9 日
編集済み: Jaya 2021 年 9 月 9 日
Thanks! Through this, I was able to find the error I was making.
And maybe you can comment the 'whose index' line. Just to not cause error for future users who might directly copy paste this code snippet.
Chunru
Chunru 2021 年 9 月 9 日
It should be "whos index" to show the variable information when an error is catched.
Jaya
Jaya 2021 年 9 月 9 日
Oh ok. That's what I thought later. Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2021 年 9 月 8 日

コメント済み:

2021 年 9 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by