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

What is the official Matlab way to plot the values of histcounts into a histogram with any normalization option?
Matlab - add custom check to model advisor
MATLAB: Retrieving GUI data from a loop
“Steepest Descent Help” — How to run steepest descent method?
Calculating Lyapunov Exponesnts for coupled system (jerk circuit)
Find the row/column of all maximum values in each row of a matrix
why Is blkdiag showing error?
Matlab get rbbox (ROI) in pixels of the image inside the figure
How to crop polygonal shape(showed in below image) in an image in MATLAB?
Resolve by dichotomy step size in steepest descent method in Matlab
Optimizing Matlab Code run time
Recovering time function from its single-sided spectrum + its Hermitian
Sum of values of Fields in Structure | Matlab
Creating a movie of histograms in matlab
Length scaling orientation data in MATLAB
Speeding up Octave / Matlab plot

Categories

HOME
asp.net-mvc
mongodb
angular2-forms
bolt-cms
path
garbage-collection
linear-programming
asana
quickblox
stack
libreoffice
winsql
delphi-xe7
restsharp
sweetalert
uwsgi
w3.css
aac
command-line-arguments
google-cloud-sdk
pyfftw
installer
raspberry-pi2
jgit
slowcheetah
appcelerator-alloy
collision
rtp
sfsafariviewcontroller
nxbre
haml
pcap
accelerated-mobile-page
mlr
jcrop
centos6
unsigned-integer
codeceptjs
ruamel.yaml
concurrenthashmap
instance
background-process
bcel
knowledge-management
csr
azure-management-api
php-5.5
projection
textangular
integer-programming
zuul
ewsjavaapi
smartbanner
a-star
getelementbyid
asp.net-mvc-custom-filter
geneticsharp
activity-diagram
securesocial
activemodel
accounts
database-tuning-advisor
maven-cargo
boost-coroutine
data-science-studio
openxls
imake
applicationstate
gnat
mklink
imaging
publish-actions
datacontractserializer
spread-toolkit
pkcs#10
keyboard-navigation
grunt-contrib-copy
delphi-2009
pdf-scraping
emitmapper
datasift-python
hresult
sparc
geometry-surface
google-chrome-frame
sender
pixelsense
jmdns
cocosbuilder
lungojs
mysql-backup
jsr223
graphiti-js
cellid
intel-8080
proxy-classes
katta
sloc
time-estimation

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