find values from array
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Mark Rzewnicki
2019-10-24
Here's a "quick and dirty" approach.
TT = [ 1 0 1 0 5 59 59 299 59 5 952 69 6 5 8 289 2 8 52 5 1 7 7 5 2 8 2 1 1 2 6 9 7 5 2 1000 5 8 95 1825];
NN = 1:1:40;
%% threeMax and twoMin will be used to store the max and min values
threeMax = zeros(1,3);
twoMin = 100*ones(1,2);
max1index = 0;
max2index = 0;
max3index = 0;
min1index = 0;
min2index = 0;
%% loop logic to rank largest 3 elements in descending order
for i = 1:1:length(TT)
if TT(i) > threeMax(1)
threeMax(3) = threeMax(2);
max3index = max2index;
threeMax(2) = threeMax(1);
max2index = max1index;
threeMax(1) = TT(i);
max1index = i;
elseif TT(i) > threeMax(2)
threeMax(3) = threeMax(2);
max3index = max2index;
threeMax(2) = TT(i);
max2index = i;
elseif TT(i) > threeMax(3)
threeMax(3) = TT(i);
max3index = i;
else
end
end
%% loop logic to locate the 2 smallest nonzero elements
for i = 1:1:length(TT)
if TT(i) < twoMin(1) && TT(i) > 0
twoMin(1) = TT(i);
min1index = i;
elseif TT(i) < twoMin(2) && TT(i) > 0
twoMin(2) = TT(i);
min2index = i;
else
end
end
stem(NN,TT);
hold on
stem([max1index max2index max3index],threeMax)
stem([min1index min2index],twoMin)
legend ('all values','max values','min values')
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!