Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matlab 2014a中滑动窗口查找最小值_Python_Matlab_Sliding Window - Fatal编程技术网

Python 在matlab 2014a中滑动窗口查找最小值

Python 在matlab 2014a中滑动窗口查找最小值,python,matlab,sliding-window,Python,Matlab,Sliding Window,我是matlab新手,我想知道我有没有办法做到以下几点: 获取我的数据中每180个样本的最小值索引列表,其长度为18000个样本 这就是我,这是我过去用python(使用numpy.where)做的,但现在我尝试用matlab做。请帮忙 dips=numpy。其中((SmoothInvelop[180:-180]

我是matlab新手,我想知道我有没有办法做到以下几点:

获取我的数据中每180个样本的最小值索引列表,其长度为18000个样本

这就是我,这是我过去用python(使用numpy.where)做的,但现在我尝试用matlab做。请帮忙

dips=numpy。其中((SmoothInvelop[180:-180]<7))[0]+180#7是一个阈值示例


下面是一个使用循环的解决方案。它还可以定义步长

%输入。
x=圆形(兰特(20,1)*100)
%窗口大小。
ws=5;
%步长。
ss=1;
%元素数。
nx=努美尔(x);
%结果元素的数量。
ny=numel(1:ss:(nx-ws+1));
%初始化输出。
y=零(ny,1);
%计算输出。
jj=1;
对于ii=1:ss:(nx-ws+1)
ww=x(ii:(ii+ws-1));
[~,yLoop(jj)]=min(ww);
yLoop(jj)=yLoop(jj)+ii-1;
jj=jj+1;
结束
%输出。
Y
存储在
y
中的最小值索引与原始输入
x
有关

ws=5和
ss=1的输出:

x=
88
74
96
31
6.
67
98
92
69
49
12
28
43
87
68
49
20
98
83
62
y=
5.
5.
5.
5.
5.
10
11
11
11
11
11
12
17
17
17
17
编辑 我添加了一个使用索引的版本,这对于大型输入来说要快得多

%输入。
x=圆形(兰特(20000,1)*100);
%窗口大小。
ws=5;
%步长。
ss=1;
%元素数。
nx=努美尔(x);
%---使用循环的解决方案---%
%结果元素的数量。
ny=numel(1:ss:(nx-ws+1));
%初始化输出(循环)。
YLOP=零(ny,1);
抽搐
%计算输出。
jj=1;
对于ii=1:ss:(nx-ws+1)
ww=x(ii:(ii+ws-1));
[~,yLoop(jj)]=min(ww);
yLoop(jj)=yLoop(jj)+ii-1;
jj=jj+1;
结束
tLoop=toc;
%输出(循环)。
洛普;
%---使用索引的解决方案---%
抽搐
%计算指数。
ind=1:ss:(nx-ws+1);
ind=repmat(ind,ws,1)+([0:(ws-1)]。*one(1,numel(ind));
%计算输出(索引)。
[~,yIndexing]=min(x(ind));
yIndexing=(yIndexing+(0:ss:(ss*(大小(ind,2)-1)));
tIndexing=toc;
%比较循环和索引版本。
fprintf(“yLoop==yIndexing:%d\n”,和(yLoop==yIndexing)==ny);
fprintf(“yLoop时间:%f s\n”,tLoop);
fprintf(“yIndeing时间:%f s\n”,tIndexing);
对于
n=20000
ws=5
ss=1
,我们得到以下时间:

yLoop时间:0.672510s
阴灯时间:0.004466秒

对于不相交的块,只需重塑矩阵的形状,使每个块成为一列,然后计算每列的arg min:

[~, indices] = min(reshape(data,N,[]), [], 1);
[~, indices] = min(data(bsxfun(@plus, 1:numel(data)-N+1, (0:N-1).')), [], 1);
给予

对于滑块,创建索引矩阵,然后沿每列计算arg min:

[~, indices] = min(reshape(data,N,[]), [], 1);
[~, indices] = min(data(bsxfun(@plus, 1:numel(data)-N+1, (0:N-1).')), [], 1);
给予


谢谢你,先生,但是当我停留的时候,我想得到这些最小值的指数,我用了find(y(jj)),但我想我仍然不知道如何正确使用它,因为它给了我所有1Ah,对不起,我错过了!将尽快尝试提供更新的解决方案。更新了我的解决方案-对于初始的、不完整的答案,再次表示抱歉@现在,两个版本——循环和索引——都应该正常工作。
indices =
     4     3     4     3     2     1     4     4     3