matlab


finding the max index in a moving window


I want to find the max element's index for a moving window. I tried to do it as the following (a simple example):
x=[1,2,3,4,5,6,7,8,9];
[m,I]=max(x(1:5))
ans
m=5
I=5
then if I say
[m2,I2]=max(x(3:7));
I get
ans
m2=7
I2=5
I want a way to give me the index with reference to the original big vector not the subvector which was passed to the function (I want I2 to give me 7 not 5).
Is there a way to do so?
Thanks
You can do something like this:
x = [2,5,6,8,4,5,10,33];
start_w = 4;
end_w = 7;
[m,I] = max(x(start_w:end_w));
I = I + start_w - 1; %reindex to x, so that x(I)==m
you can use sliding window operation to get the local max indexes and add the global window xenter indexes afterwards:
function idx = maxidx(x)
[~,idx] = max(x);
and:
x = [1,2,3,4,5,6,7,8,9,1,3]; % test array
W = 5; % window width
% moving max idx function -> local indexes
B = colfilt(x,[1 W],'sliding',#maxidx);
% index addition to convert local indexes to global
addedIdx = (1:length(x)) - floor((W+1)/2);
% add local indexes with global addition
res = B + addedIdx
res =
3 4 5 6 7 8 9 9 9 9 9

Related Links

Out of memory TriScatteredInterp in Matlab
Labelling a plotmap of self organizing map in Matlab(edited)
Least absolute deviation regression in matlab
How to implement an “importable namespace”?
Chain rule with symbolic function in Matlab
How to merge numerical cell and char cell of binary values into 1 cell in matlab
create subplot with loop
avoid the 'for' loop in matlab script by permuting
Obtaining the forecasted future values for a time series using neural networks in Matlab
assign parameters for cluster job with slurm sbatch
Eigen Convert Matrix to Vector
Opening remote files with local Matlab
solve 3 equation in Matlab for 2 variables
fopen file alredy fopened through input command in matlab
matlab - plot inequality in 3d with surf
Reading text from multiple text files at the same time and splitting them into array of words

Categories

HOME
hadoop
wix
whatsapp
gwt
android-sqlite
svg.js
addeventlistener
spi
sony-camera-api
build.gradle
google-adwords
splunk
py.test
superfish
openframeworks
frequency
javers
hp-alm
windows-applications
netcdf
php-carbon
smallbasic
esri
regex-group
text-parsing
android-button
nested-loops
webfocus
asp.net-identity-2
dapper-fastcrud
petrel
tensor
server-sent-events
doctrine-odm
hamcrest
draggable
protobuf-3
extjs4
compass-lucene
mdanalysis
syncfusion
codeigniter-hmvc
kendo-chart
database-cleaner
ietf-netconf
android-camera-intent
singlepage
mapr
django-errors
topojson
directsound
rsh
formatter
cover
facebook-comments
okuma
aplpy
tag-helpers
document-ready
equinox
maven-cargo
vbo
sketching
spatial-index
ehcache-bigmemory
targetinvocationexception
computer-science-theory
boxapiv2
symfony-2.5
knockout-mvc
cpp-netlib
custom-titlebar
hebrew
windows-phone-7.1
data-dictionary
freemind
couchrest
libtorrent-rasterbar
prudentia
external-dependencies
zephir
hresult
argumentexception
godaddy-api
impdp
sizzle
calloc
objcopy
livevalidation
having
unitils
excel-web-query
pinging

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App