Please Help! GUI problem for 'function varargout = NNEW(varargin) | Error: Function definitions are not permitted in this context.'

10 visualizaciones (últimos 30 días)
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 comentario
Adam Danz
Adam Danz el 21 de Jun. de 2018
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()

Iniciar sesión para comentar.

Respuestas (1)

OCDER
OCDER el 21 de Jun. de 2018
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]');

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by