From: Mike Bourassa on
I have a 3D array part of which is provided below. I want to find the max value in col #1 and return the associated value in col #3. I can do this sequentially using a loop but at 100,000 arrays it takes a long time. Can this operation be vectorized?

I am using Matlab R14 on Win2K with 2GhZ Athlon and 2 GB RAM.

Any assist/hint would be appreciated.


ans(:,:,1) =

0 7.0000 -0.1210
4.0000 12.0000 0.3114
0 11.0000 0.2144
0 3.0000 -0.6723
0 2.0000 -0.7173
0 14.0000 0.3820
1.0000 10.0000 0.1524
0 8.0000 -0.1236
15.0000 16.0000 1.0352
0 4.0000 -0.3511
0 5.0000 -0.3483
0 9.0000 0.0098
1.0000 15.0000 0.8624
0 1.0000 -0.7133
0 13.0000 0.4283
0 6.0000 -0.3487


ans(:,:,2) =

0 3.0000 -0.5904
14.0000 15.0000 0.9299
1.0000 11.0000 0.3627
0 4.0000 -0.6486
0 6.0000 -0.3445
0 7.0000 -0.3803
3.0000 14.0000 0.6902
0 10.0000 0.2323
9.0000 16.0000 1.0095
3.0000 12.0000 0.3947
0 1.0000 -0.7477
6.0000 13.0000 0.5846
0 9.0000 -0.2182
0 7.0000 -0.3020
0 6.0000 -0.2855
0 2.0000 -0.6864


ans(:,:,3) =

0 4.0000 -0.5724
14.0000 15.0000 0.9248
1.0000 11.0000 0.3625
0 3.0000 -0.6885
0 5.0000 -0.3672
0 6.0000 -0.3781
4.0000 14.0000 0.6640
2.0000 10.0000 0.2652
9.0000 16.0000 1.0079
1.0000 12.0000 0.3513
0 1.0000 -0.7321
5.0000 13.0000 0.5925
0 9.0000 -0.2245
0 8.0000 -0.2799
0 7.0000 -0.2540
0 2.0000 -0.6712
From: Jan Simon on
Dear Mike,

> I have a 3D array part of which is provided below. I want to find the max value in col #1 and return the associated value in col #3. I can do this sequentially using a loop but at 100,000 arrays it takes a long time. Can this operation be vectorized?

What is "col #1"?
Finding the index of the maximum value is performed by the command MAX:
x = rand(4,5,3);
[maxValue, maxIndex] = max(reshape(x(1, :, :), 1, [])); % Is this "col #1" ?!
x_3 = x(3, maxIndex);
Perhaps this helps, although I have the impression, that your col #1 is something else.

Jan