Unless you have good reasons to use cell arrays, then the simplest answer is to store your data in one numeric array and use the standard MATLAB command min . If the data is of different lengths, you can pad the rows/columns/etc with NaN's, and use nanmin . Both of these will be a million times faster and neater than playing around with cell arrays. Previous questions you have asked on MATLAB Answers have shown an over-reliance on cell arrays, when using numeric arrays would make your own life so much easier. Cell arrays are not mandatory for MATLAB coding, and MATLAB works best when using vectorized code directly on numeric arrays. Please consider this carefully! As I understand it, you are wanting to locate the minimum positive value of all numeric arrays that are contained in one cell array, and to know its indices. This is just an exercise in keeping track of indices:
A = num2cell(reshape(randperm(12)-6,[],2),2);
V = cellfun(@(a)find(a>0), A, 'UniformOutput',false);
W = find(~cellfun('isempty',V));
[X,Y] = cellfun(@(a,v)min(a(v)), A,V, 'UniformOutput',false);
[a1,Z] = min([X{W}]);
x1 = W(Z);
c1 = V{x1}(Y{x1});
A{x1}(c1)
As you are not very specific about the exact problem, I have assumed that A is a vector, that the minimum positive value occurs only once, and that there is always at least one positive value in at least one numeric array.
Of course doing this with a simple numeric array makes your life much easier, as you could do something like this:
E = vertcat(A{:});
F = find(E>0);
[a2,G] = min(E(F));
[r2,c2] = ind2sub(size(E),F(G));
Note that the indices are the same: c1==c2, x1==r2, and a1==a2.
Best Answer