Index exceeds matrix dimensions error

hi i was running this simple code,but i got this error,any idea how to fix it?
L = 140; % Length of signal
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
YY = fft(rawdata,NFFT)/L;
((((((((((Index exceeds matrix dimensions.))))))))
Error in Untitled2 (line 11)
YY = fft(rawdata,NFFT)/L;

4 Comments

Before the YY line, put this and tell us what it says
whos rawdata
NFFT
Is NFFT > the dimensions of rawdata?
thanks for your fast reply, i did what you said,here are the result
Name Size Bytes Class Attributes
rawdata 140x1 1120 double
NFFT =
256
Next step:
In the Command Window, type
which fft -all
after the error.
I get 6 answers, all in: C:\Program Files\MATLAB\.
fft is a variable.
built-in (C:\MATLAB\R2012a\toolbox\matlab\datafun\@logical\fft) % Shadowed logical method
built-in (C:\MATLAB\R2012a\toolbox\matlab\datafun\@single\fft) % Shadowed single method
built-in (C:\MATLAB\R2012a\toolbox\matlab\datafun\@double\fft) % Shadowed double method
C:\MATLAB\R2012a\toolbox\matlab\datafun\@uint8\fft.m % Shadowed uint8 method
C:\MATLAB\R2012a\toolbox\matlab\datafun\@uint16\fft.m % Shadowed uint16 method
C:\MATLAB\R2012a\toolbox\comm\comm\@gf\fft.m % Shadowed gf method
C:\MATLAB\R2012a\toolbox\distcomp\parallel\@codistributed\fft.m % Shadowed codistributed method
C:\MATLAB\R2012a\toolbox\dsp\filterdesign\@qfft\fft.m % Shadowed qfft method
C:\MATLAB\R2012a\toolbox\ident\ident\@iddata\fft.m % Shadowed iddata method

Sign in to comment.

 Accepted Answer

How can you take 256 samples from an array with 140 samples? Maybe you need to pad it with zeros or something
newArray = [oldArray, zeros(1, NFFT - length(oldArray))];

6 Comments

Actually it says it does the padding for you so you should be okay: "Y = fft(X,n) returns the n-point DFT. fft(X) is equivalent to fft(X, n) where n is the size of X in the first nonsingleton dimension. If the length of X is less than n, X is padded with trailing zeros to length n. "
Try Star's suggestion of
which -all fft
And see if it says this:
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datafun\@logical\fft) % logical method
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datafun\@single\fft) % single method
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datafun\@double\fft) % double method
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datafun\@uint8\fft.m % uint8 method
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datafun\@uint16\fft.m % uint16 method
or does it have some folders with your name in them?
thanks for your replay i did what u said,and pad it with zeros but i got this new error
Error using horzcat CAT arguments dimensions are not consistent.
Error in Untitled2 (line 11) newArray = [rawdata, zeros(1, NFFT - length(rawdata))];
i tried 'which -all fft' i had all the files that you mentioned
Like Star said, you have a variable called fft, apparently in some code you didn't show us. Rename that variable.
my vector was a column vector and could not be concatenated with row vector zeros(1, NFFT - length(rawdata)).so i changed it to zeros(NFFT - (length(rawdata)), 1)]; and it works properly thanks indeed for your fast replays
OK, glad it works, though I don't know why since the help for fft() said that it would do that padding for you.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!