How do I fix the error "Unexpected MATLAB Operator?"
Show older comments
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
on 1 Jul 2013
If you run the program, is the error reported against any particular line?
You could get problems if your startup.m had invalid syntax.
Answers (1)
Image Analyst
on 1 Jul 2013
0 votes
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
Andrew
on 1 Jul 2013
Image Analyst
on 1 Jul 2013
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.
Andrew
on 1 Jul 2013
Walter Roberson
on 1 Jul 2013
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
on 1 Jul 2013
Image Analyst
on 1 Jul 2013
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.
Categories
Find more on Simulink 3D Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!