What does parse error basically mean?

661 Ansichten (letzte 30 Tage)
Maheen
Maheen am 5 Jul. 2014
Kommentiert: Image Analyst am 16 Jul. 2022
I just wanted to clarify in very layman terms what is a parse error?

Antworten (3)

James Tursa
James Tursa am 5 Jul. 2014
When did you get this error? In general, the term "parsing" refers to MATLAB reading an m-file (script or function) and translating it into an internal code that it stores in memory. It is this "parsed" file in memory that is actually run when you execute the code.

Image Analyst
Image Analyst am 5 Jul. 2014
You might have some code that throws an exception (generates an error) like this:
try
% Some code that might generate an error.
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
The error here is a string in ME.message. Parse it means that you might look at the error and try to recognize certain words and take action based upon what you find. For example you might have an error that says this:
Error using imread (line 349)
File "sss.dd" does not exist.
and you might want to do some particular thing, like alert the programmer that the file doesn't exist and to make sure the folder is prepended to the filename
if ~isempty(strfind('does not exist') ) % Parse error message
warndlg(..............

Angie
Angie am 16 Jul. 2022
error: parse error: syntax error >>> y3 = sin(x)cos(x); ^ error: 'y3' undefined near line 1, column 1 warning: legend: ignoring extra labels warning: called from __gnuplot_legend__ at line 490 column 13 legend at line 198 column 37
  1 Kommentar
Image Analyst
Image Analyst am 16 Jul. 2022
You'd need a .* between sin and cos like
y3 = sin(x) .* cos(x);
Of course x also needs to be defined before that line.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by