MATLAB Answers

Jason
0

Problem with diff operating on a row vector from regionprops

Asked by Jason
on 5 Sep 2019
Latest activity Commented on by Jason
on 5 Sep 2019
Hello, I have an image which consists of 4 spots that I apply regionprops to:
area_measurements = regionprops(BW2,I,{'Area','Perimeter','MajorAxisLength','MinorAxisLength','Orientation','Eccentricity'});
I want to remove any spots that are different to the others. e.g the top left spot
I decided to use Major and Minor as my metric.
allMajor=[area_measurements.MajorAxisLength]
allMinor=[area_measurements.MinorAxisLength]
allMajor =
272.44 227.15 264.20 264.85
allMinor =
197.26 81.16 185.93 205.54
And then combine them, so
MM=[allMajor.*allMinor]
MM =
53742.57 18435.82 49121.64 54437.08
and then calc their differences to be able to remove the worst one. (I was thinking to remove the one with the largest difference and then take the mean)
y=diff(MM)
But this gives me an error:
Array indices must be positive integers or logical values.
I can't see why this is the case.

  0 Comments

Sign in to comment.

1 Answer

Answer by Nicolas B.
on 5 Sep 2019
Edited by Nicolas B.
on 5 Sep 2019
 Accepted Answer

Hi Jason,
I tried the following code:
MM = [53742.57, 18435.82, 49121.64, 54437.08];
y = diff(MM);
I get the following answer:
y =
1.0e+04 *
-3.5307 3.0686 0.5315
Are you sure that you don't have a variable or one of your functions that is named diff? It could be that you are shadowing the diff function.

  1 Comment

AAhhh...yes I do, thanks for this
Jason

Sign in to comment.