error while running watershed

My code:
im2=~im1;
%imshow(im2,[])
D=- bwdist(im2);
%imshow(D,[])
im3= watershed(D);
The error message:
Error: File: conndef.m Line: 1 Column: 1
Unexpected MATLAB operator.
Error in watershed>parse_inputs (line 158)
conn = conndef(ndims(A), 'maximal');
Error in watershed (line 140)
[A,conn] = parse_inputs(varargin{:});
Error in dicom (line 87)
im3= watershed(D);
I can't figure what the problem is.

Answers (1)

DGM
DGM on 11 Jun 2021
Edited: DGM on 11 Jun 2021
I don't know how you'd be getting that error unless there's a problem with conndef.m
Maybe it's being shadowed, so check the path:
which conndef -all
/MATLAB/toolbox/images/images/conndef.m
If you have some other file that's overloading conndef.m, you'll have to remove it from the path or reduce its precedence.
Maybe it's a bad install or corruption? You can look at the file by opening it, or just fetch the first line and see if it makes sense. The IPT version at the above path would look like this:
fid = fopen('conndef.m');
a = fgetl(fid);
fclose(fid);
a
a = 'function conn = conndef(num_dims,type)'
That's my guess.

12 Comments

Votre code ne compile pas. J'ai supprime le second fichier et toujours rien
Not enough input arguments.
Error in run (line 28)
if isempty(scriptname)
Error in dicom (line 85)
run
DGM
DGM on 11 Jun 2021
Edited: DGM on 11 Jun 2021
which conndef -all
Should definitely return something. Your original error verifies that there is a function called conndef on the path.
The error in the above comment isn't related to either your original posted code or my posted code. It's just plain invalid usage of run(). You need to specify the file when using run(). See help run
fid = fopen('conndef.m');
a = fgetl(fid);
fclose(fid);
im2=~im1;
%imshow(im2,[])
D=- bwdist(im2);
%imshow(D,[])
im3= watershed(D);
Error: File: conndef.m Line: 1 Column: 1
Unexpected MATLAB operator.
Error in watershed>parse_inputs (line 158)
conn = conndef(ndims(A), 'maximal');
Error in watershed (line 140)
[A,conn] = parse_inputs(varargin{:});
Error in dicom (line 89)
im3= watershed(D);
This is basic troubleshooting. These steps I'm suggesting aren't going to instantly fix your script, so don't try to just paste them into it. You just need to run them and observe the output.
Pasting them into the console should suffice. My answer shows what should be printed when the code is run in the console. The first line should give the paths to all files called conndef. The second should return line 1 from the version of conndef with the highest precedence. That information is key to finding out why conndef isn't working.
J'ai teste le code:
fid=fopen('conndef.m');
a=fgetl(fid);
fclose(fid);
et j'ai fid=3 et a= 1*1256 char
Je suppose que j'ai 3 fichiers conndef.m mais comment les voir?
The number 3 returned by
fid=fopen('conndef.m');
is just a handle. It's not the number of files.
If you run
which conndef -all
it should tell you where all the files are and which one is being used.
But yes, you do appear to have a conflicting version of the file somewhere.
J'ai essaye conndef -all sans resultat. Etrange!
fid=fopen('conndef.m');
a=fgetl(fid);
fclose(fid);
conndef -all
L'erreur:
>> newfile
Error: File: conndef.m Line: 1 Column: 1
Unexpected MATLAB operator.
Error in newfile (line 4)
conndef -all;
The command is
which conndef -all
(case-sensitive)
Just paste it in the console and hit enter. Don't bother trying to put it into the script. Just run it by itself.
There should be at least 1 result.
J'obtiens toujours une erreur
>> conndef -all
Error: File: conndef.m Line: 1 Column: 1
Unexpected MATLAB operator.
You forgot the which
which -all conndef
^^^^^^^

Sign in to comment.

Products

Release

R2017b

Asked:

on 11 Jun 2021

Edited:

on 23 Jun 2021

Community Treasure Hunt

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

Start Hunting!