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

Asked by Andrew about 12 hours ago
Latest activity Commented on by Image Analyst about 11 hours ago

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

Walter Roberson about 12 hours ago

If you run the program, is the error reported against any particular line?

You could get problems if your startup.m had invalid syntax.

Andrew

Products

No products are associated with this question.

1 Answer

Answer by Image Analyst about 12 hours ago

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

Walter Roberson about 11 hours ago

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.

Andrew about 11 hours ago

Thanks. I didn't realize that the title started with a number and that it might've been the problem.

Image Analyst about 11 hours ago

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.

Image Analyst

Contact us