Please Help! GUI problem for 'function varargout = NNEW(varargin) | Error: Function definitions are not permitted in this context.'
10 ビュー (過去 30 日間)
古いコメントを表示
Hi! I'm new to Matlab and working on a group assignment problems. My friends sent me these coding and I try to run it When i try to run n stimulate the coding below. This kind of error occurs. Any solution to solve it?
1 件のコメント
Adam Danz
2018 年 6 月 21 日
It looks like this was written using GUIDE which also produces a figure (.fig) that is accessed when running this m file. I'm assuming you have that figure, too.
Check that the filename is "NNEW.m" (which is correctly named in your attachment). The filename should match the first function name in the file.
Lastly, what version of matlab are you using? To find out, open matlab and execute this command below. Your version should ideally be the same or more recent than the one used to create the GUI.
ver()
回答 (1 件)
OCDER
2018 年 6 月 21 日
How exactly are you "running" the code? The error you have now is caused when you invoke the "function" command directly.
>> function a = testFunc(a)
function a = testFunc(a)
↑
Error: Function definitions are not permitted in this context.
You can only use function to define a matlab function. To "run" a function, you call the function name WITHOUT the word function.
a = testFunc(a)
To run your GUI, type this on the command line:
>> NNEW
As what @Adam said, you must also have a NNEW.fig file so that your GUI knows what to show. The NNEW.m file only stores the codes that run behind the GUI. If you lack the NNEW.fig file, you'll get this error:
>> NNEW %lacking the NNEW.fig file
Error using load
Unable to read file 'NNEW.fig'. No such file or directory.
Error in matlab.graphics.internal.figfile.FigFile/read (line 31)
hgDataVars = load(filename, '-mat', '-regexp', '^hg[M]');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!