|
I've a litte difficulties in tackling a problem in Matlab. I think it's the easiest way to explain it in an example. In the real problem the matrix has like 200000 rows, so it's a bit bigger.
Let's say i've this matrix T :
T=
5 2
5 1.1
5 2.3
6 2
6 3
6 3.1
6 5
7 8
7 8.1
7 17
I want to get the following matrix though. In this matrix a third collumn is added. The value in this column is the minimum of all values in the second row that shear a single value in the first row. I guess this is not really clearly explained, but if you take a look you will get it. The lowest value in the second row after a '5' in the first row is 1.1...etc. So what i want to get is:
5 2 1.1
5 1.1 1.1
5 2.3 1.1
6 2 2
6 3 2
6 3.1 2
6 5 2
7 8 8
7 8.1 8
7 17 8
A very slow option is:
for a=1:size(T,1)
T(a,3)=min(T(find(T(:,1)==T(a,1)),2);
end
I wanted to vectorize this and came up with:
T(:,3)=min(T(find(T(:,1)==T(:,1)),2);
this didn't work though...any ideas are more then welcome!
|