error while running watershed
Show older comments
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)
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
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
That's my guess.
12 Comments
Audrey SCARLETT
on 11 Jun 2021
Audrey SCARLETT
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
Audrey SCARLETT
on 11 Jun 2021
Audrey SCARLETT
on 11 Jun 2021
DGM
on 11 Jun 2021
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.
Audrey SCARLETT
on 14 Jun 2021
DGM
on 14 Jun 2021
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.
Audrey SCARLETT
on 14 Jun 2021
DGM
on 14 Jun 2021
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.
Audrey SCARLETT
on 14 Jun 2021
Image Analyst
on 23 Jun 2021
Edited: Image Analyst
on 23 Jun 2021
You forgot the which
which -all conndef
^^^^^^^
Categories
Find more on Morphological Operations 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!