Please help me with the error : "Parse error at numargin: usage might be invalid MATLAB syntax"

My project is "GUI Based Home Automation System using Arduino and MATLAB" , after creating the gui file, the file gui_mainfnc.m appears with the word "numargin" ( in the code below). Then, MATLAB requires me to fix the error due to "Parse error at numargin: usage might be invalid MATLAB syntax". Because this file is created automatically, I dont know how to fix this.

6 件のコメント

Walter Roberson
Walter Roberson 2019 年 8 月 12 日
Is there a reason you are not using nargin ?
Dung Dang
Dung Dang 2019 年 8 月 12 日
thank you very much for your advice but when I change "numargin" to "nargin" the error is still the same "Parse error at nargin: usage might be invalid MATLAB syntax". I really dont know what is actually happening
Until you fix the "end", the error is going to continue to occur.
I think you need to change
isequal(gui_Statefields(i), 'gui_Name')
to
if isequal(gui_Statefields(i), 'gui_Name')
Dung Dang
Dung Dang 2019 年 8 月 13 日
I'm so sorry fro replying you so late. tomorrow is my project's deadline so I'm begging for your help again. I've changed just like what you told me to do however the error "nargin" is still the same. You can see here:ask again.PNG
Change this
nargin=length(varagin);
if numargin ==0
To this
if nargin == 0
You misspelled varargin and you didn't use the variable you just created. And you don't need to do either.
Dung Dang
Dung Dang 2019 年 8 月 13 日
It seems like changing does not work. Thank you so much for your enthusiasm but this is the only error I encounter in this file. So would you mind helping me ?ask again 1.png

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

 採用された回答

Steven Lord
Steven Lord 2019 年 8 月 13 日

1 投票

Smart indent your code and you should see that you have an extra end. The end on line 45 ends the for loop "for i=1:length(gui_StateFields)" and the end on line 46 likely ends the main function in the file. Therefore your nargin call is outside any function and that's not allowed.
Try deleting the end on line 46 and smart indent again. Once you do that each end should line up with the if, for, or function keyword to which it corresponds.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 12 日

1 投票

isequal() is a comparison. There is seldom a benefit to using isequal() in an expression by itself except for debugging.
Count your statement nesting. "for i" gets you to nesting level 1. 'if i==" gets you to nesting level 2. The "end" after the error() gets you back to nesting level 1. The "isequal" does not change the nesting level. The assignment to gui_Mfile does not change the nesting level, but it is deceptively indented. The "end" after that assigment matches the "for i" statement and takes you to nesting level 0. Then the "end" after that has nothing to match up to and gives you an error.
I would suggest to you that you have accidentally deleted an "if" in the isequal() line.

カテゴリ

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

タグ

質問済み:

2019 年 8 月 12 日

回答済み:

2019 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by