日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab寻找向量最小值,matlab – 在排序向量中快速搜索大于x的最小值

發布時間:2023/11/30 循环神经网络 67 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab寻找向量最小值,matlab – 在排序向量中快速搜索大于x的最小值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

由于輸入已經排序,自定義二進制搜索應該有效(您可能需要對邊緣情況進行一些更新,即請求的值小于數組的所有元素):

function [result, res2] = binarySearchExample(val)

%// Generate example data and sort it

N = 100000000;

a = rand(N, 1);

a = sort(a);

%// Run the algorithm

tic % start timing of the binary search algorithm

div = 1;

idx = floor(N/div);

while(1)

div = div * 2;

%// Check if less than val check if the next is greater

if a(idx) <= val,

if a(idx + 1) > val,

result = a(idx + 1);

break

else %// Get bigger

idx = idx + max([floor(N / div), 1]);

end

end

if a(idx) > val, % get smaller

idx = idx - floor(N / div);

end

end % end the while loop

toc % end timing of the binary search algorithm

%% ------------------------

%% compare to MATLAB find

tic % start timing of a matlab find

j = find(a > val, 1);

res2 = a(j);

toc % end timing of a matlab find

%// Benchmark

>> [res1, res2] = binarySearchExample(0.556)

Elapsed time is 0.000093 seconds.

Elapsed time is 0.327183 seconds.

res1 =

0.5560

res2 =

0.5560

總結

以上是生活随笔為你收集整理的matlab寻找向量最小值,matlab – 在排序向量中快速搜索大于x的最小值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。