How do I fix the error "Unexpected MATLAB Operator?"

Unexpected MATLAB Operator when running MATLAB. After fixing the path, we still recieve the same error. This code is designed to analyze frames and calculate the RMS deviation in the Y direction.
S1= 1; % The frame on which you begin.
N1= 900; % The frame on which you end.
Nx= 30; % The x and y spread that will be cut out of the frames.
Ny= 30;
xc= 351; % One must manually find and enter the center position (xc, yc).
yc= 319;
res= zeros(N1-(S1-1),2); % Stores the position data.
spark= zeros(N1-(S1-1),1); % Creates a matrix for just Y values
count= 1; % The count of the valid pictures, starting at 1.
for framenum= S1:N1
Im= imread(sprintf('6.27.13 - 3 ~ Water _ %04d.jpeg', framenum)); % Imports the figures one by one.
im= Im(yc-Ny:yc+Ny,xc-Nx:xc+Nx); % Takes the particles out of the frame.
bwi= im2bw(im,220/255); % This is used to separate the particle from the background.
% If the background is 175, then this
% number is 200 (or you can use another
% number, but make sure this number is
% between the particle's edge
% brightness and the background's).
bwi= bwareaopen(bwi,10); %Gets rid of <10 pixel noise points.
bwi= imfill(bwi,'holes'); %If the particle shows a donut shape, fills the center hole
B= bwboundaries(bwi,'noholes'); % This gets the particle's boundary coordinates and stores
% them in a cell array. In each
% cell is a Qx2 matrix, where Q is
% the number of boundary pixels.
szB= size(B);
if szB(1)>0 % Requires that a particle be found.
s1=B{1}; % The boundary matrix of the particle
y1= mean(s1(:,1)); % The x postion of the first particle
x1= mean(s1(:,2)); % The y postion of the first particle
res(count,1)= xc-Nx+x1; % Stores the actual positions in the original picture
res(count,2)= yc-Ny+y1;
spark(count,1)=yc-Ny+y1; % Stores the Y positions in a separate matrix
xc= round(xc-Nx+x1); % Relocates the center for the next frame
yc= round(yc-Ny+y1);
end
count= count+1; % Increase the count for the next frame
end
idx= ~res;
res(idx)= nan;
Y=rms(spark); % Calculates RMS for Y values

1 Comment

If you run the program, is the error reported against any particular line?
You could get problems if your startup.m had invalid syntax.

Sign in to comment.

Answers (1)

Look in the right hand side of your editor window for the red line and click on it to go to the offending line. Then fix it. It probably has bad syntax. If you hover over the red squiggle, you may see a popup window with an offer to fix the error based on what it thinks the solution might be.

6 Comments

There isn't a red line or bad syntax; however, there's always a problem with the path that may be causing the unexpected operator. I don't know if this is unrelated. There may be a simple error I'm overlooking due to my inexperience.
We can't run your code - too many undefined variables. What is the exact error message. You didn't give it - you just clipped out a small portion of the complete error message and told us that small portion so we don't know where the actual problem lies.
The undefined variable are parts of the image (ie. coordinates, brightness, and centers of obejct). The program is designed to track spheres as they move across the screen. The exact error is ??? 1DA | Error: Unexpected MATLAB operator.
Does it give a line number and a routine name?
The "1DA" is the content of the line it found. As you do not appear to have "1DA" in your code, it must be in some other routine; it should be telling you the name and line number of the active routine where it encountered the problme.
If you go to the command window and put in the name of your .m file, without the ".m", what comes up?
Question: what is the exact name of your .m file? .m filenames must begin with a letter and have only letters and numbers and underscore (other than the period for .m); there must not be a space in the name.
Thanks. I didn't realize that the title started with a number and that it might've been the problem.
Glad you found the source of the error, but in the future when we say the exact error we mean all the text that is in red, which includes the lines of code that were called as well as their line numbers - not at all what you gave in your second response when I asked you for it.

Sign in to comment.

Asked:

on 1 Jul 2013

Community Treasure Hunt

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

Start Hunting!