Your code

```
sum(a(2,:)~=1)
```

tells you *how many* entries in the second row are not the minimum of 1. That's because the argument to `sum`

,

```
>> a(2,:)~=1
ans =
1 1 1 0
```

is a logical array that indicates whether each of the numbers in that row is different from 1, and the logical values false and true are interpreted as numbers 0 and 1 by `sum`

.

What you want to do is use these values for *logical indexing* into the row, and summing only the selected elements

```
ind = a(2,:)~=1;
sum(a(2,ind))
```

or shorter

```
sum(a(2,a(2,:)~=1))
```

Of course for generality it would be better to replace `1`

by the expression `min(a(2,:))`