Q:

How can I find the indices of the 2 smallest elements in a vector without sorting?

I'm trying to find the two smallest elements of a 1xn vector.  The catch is that I can't sort it because the indices are linearly dependent upon the values (so sorting the values will screw up to original indices) AND 0 can be one of the elements.  Also, elements can repeat.  Here's a simplified example of my code:
a = [1,5,8,7,1];

find(a==min(a))

ans =

 1     5

For a, this is the answer I was expecting.
b = [0,8,6,1,9];

find(b==min(b))

ans =

 1

For b, I need it to find the 0 and the 1 so it should give me back 1 and 4 respectively for the indices. Thanks in advance!

A:

You should use the second output from sort,
>> [~,idx] = sort(a);
>> idx(1:2)
ans = 
  1  5
>> [~,idx] = sort(b);
>> idx(1:2)
ans = 
  1  4

A:

Phil Goddard's answer is perfectly acceptable.  However, you did say that you want to do this without sorting, so I'm assuming you don't want to use the sort function at all.  What you can do is use min twice.  Once you invoke it the first time and you find the index of the minimum element, you would set this location in your array to NaN, then run min an additional time.  By setting the location to NaN, you would effectively skip the element that is equal to the smallest at that point in time.  After you call min the second time, you'll get the second smallest element.  
One small thing you'll need to do afterwards is to clear off the NaN you set in the array after the first min call.  You do this by extracting what the minimum value was after the first call, in addition to where this minimum value was located.  Once you call min a second time, you'd reset the location of where the first minimum was from NaN back to its original value.  
In other words:
a = [1,5,8,7,1];
[min1,ind1] = min(a);
a(ind1) = NaN;
[~,ind2] = min(a);
a(ind1) = min1; %// Copy back to ensure we get original data back

ind1 and ind2 will contain the locations of the two smallest values in a.  With your example, I get:
disp([ind1 ind2])

1     5

Similarly, for b, this is what we get with the above code:
disp([ind1 ind2])

1     4

