Cell Array min excluding zero
Ältere Kommentare anzeigen
Hi, I want to find a min value that is not 0 from a cell array that has different number of elements in it:
cost = [1*11 double]; [1*12 double]; [1*7 double] and so on
at the moment I am finding the min like this:
[M,I] = min([cost_hist{:}]);
and I tried different variations with ~= 0 with no success. The index is also important.
Thanks in advance, Asher
5 Kommentare
harjeet singh
am 28 Dez. 2015
min means the average of every mat?
Azzi Abdelmalek
am 28 Dez. 2015
For this example, what is the expected result?
a={[0 10 0 2 4] [4 3 8] [0 5 -2 15] [2 6]}
Asher Metzger
am 28 Dez. 2015
Asher Metzger
am 28 Dez. 2015
Asher Metzger
am 28 Dez. 2015
Akzeptierte Antwort
Weitere Antworten (1)
harjeet singh
am 28 Dez. 2015
you may try this
r=0;
c=0;
min_num=inf;
for i=1:size(cost,1)
for j=1:size(cost,2)
a=cost{i,j};
if(min(a(:))<min_num)
min_num=min(a(:));
r=i;
c=j;
end
end
end
display(strcat('position r:',num2str(r),'position c:',num2str(c)));
display(strcat('min number:',num2str(min_num)))
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!