MATLAB Answers


Subscript indices must either be real positive integers or logicals.pls help me with dis error

Asked by Sony
on 1 May 2013
 Subscript indices must either be real positive integers or logicals.
Error in ==> svlzfsig2>remTrend at 54
Error in ==> svlzfsig2>zeroFreqFilter at 41
Error in ==> svlzfsig2 at 17
Error in ==> EpochsbyZFF at 40
Error in ==> UVRegion at 10
Error in ==> hari_new at 36




No products are associated with this question.

2 Answers

Answer by Wayne King
on 1 May 2013

You have to tell us what the sizes are of the variables in


put a breakpoint in the code at that line and see what the dimensions are of rm and winSize


Answer by Image Analyst
on 1 May 2013

winSize is probably an odd number, like 5, so winSize/2 would be a fractional number like 2.5. There is no 2.5th element of the array. There is element #2 and element #3. You have to decide to use only even window sizes, or decide what to do in the case of an odd sized window.


Whatever code is constructing the value that gets written into winSize: change that code so that it only allows even numbers.

on 3 May 2013

function [zfSig]=zeroFreqFilter(wav,fs,winLength) dwav=diff(wav); dwav(end+1)=dwav(end); dwav=dwav/max(abs(dwav)); N=length(dwav); zfSig=cumsum(cumsum(cumsum(cumsum(dwav)))); winLength=round(winLength*fs/1000); zfSig=remTrend(zfSig,winLength); zfSig=remTrend(zfSig,winLength); zfSig=remTrend(zfSig,winLength); zfSig(N-winLength*2:N)=0; zfSig(1:winLength*2)=0; function [out]=remTrend(sig,winSize)

window=ones(winSize,1); rm=conv(sig,window); rm=rm(winSize/2:length(rm)-winSize/2);

norm=conv(ones(size(sig)),window); norm=norm(winSize/2:length(norm)-winSize/2);

rm=rm./norm; out=sig-rm; return; this is the code can u tell me where should i change such that it only allows evn numbers

When you call zeroFreqFilter(), just make sure the third argument is 2, 4, 6, 8, or any other even number. Make sure it's not 3, 5, 7, 9, or any other odd number because your program does not like that. I'm really not sure why you ask "how to to use only even window sizes?" - isn't it obvious? Or am I missing something?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!