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

Thread Subject:
Error - Index exceeds matrix dimensions..?

Subject: Error - Index exceeds matrix dimensions..?

From: John

Date: 6 Feb, 2007 05:33:28

Message: 1 of 9

Hi there, can anyone tell me what is wrong with my short piece of
code:

name = input('Please enter name of wav file to be processed
(noextension): ','s');
fname1 = [name '.wav'];
[y Fs] = wavread(fname1);
x = y([1:(30*Fs)]);
wavwrite(x,Fs,'excerpt2.wav')
Freq_Response = fft(x);
Magnitude = abs(Freq_Response);
Power = Freq_Response.*conj(Freq_Response);
Display_Freq = fftshift(Power);
Display_Freq2 = fftshift(Magnitude);
plot(Display_Freq2);

It returns the error message:

??? Error using ==> run
Index exceeds matrix dimensions.

I'm pretty sure it's something wrong with this line: x =
y([1:(30*Fs)]); ..But I really don't know what... Thanks for any
help!

Subject: Error - Index exceeds matrix dimensions..?

From: Michael Salloker

Date: 6 Feb, 2007 11:43:39

Message: 2 of 9

John schrieb:
> Hi there, can anyone tell me what is wrong with my short piece of
> code:
>
> name = input('Please enter name of wav file to be processed
> (noextension): ','s');
> fname1 = [name '.wav'];
> [y Fs] = wavread(fname1);
> x = y([1:(30*Fs)]);
> wavwrite(x,Fs,'excerpt2.wav')
> Freq_Response = fft(x);
> Magnitude = abs(Freq_Response);
> Power = Freq_Response.*conj(Freq_Response);
> Display_Freq = fftshift(Power);
> Display_Freq2 = fftshift(Magnitude);
> plot(Display_Freq2);
>
> It returns the error message:
>
> ??? Error using ==> run
> Index exceeds matrix dimensions.
>
> I'm pretty sure it's something wrong with this line: x =
> y([1:(30*Fs)]); ..But I really don't know what... Thanks for any
> help!

I suggest first to execute the expressions one by one, to be really
sure, which one causes the problem.

Michael

Subject: Error - Index exceeds matrix dimensions..?

From: Markus

Date: 6 Feb, 2007 05:51:34

Message: 3 of 9

Obviously there are no 30 seconds of sound saved in that file, i.e.
vector y is less than 30*Fs elements long.

Markus

Subject: Error - Index exceeds matrix dimensions..?

From: Anwesha

Date: 11 Dec, 2008 07:10:08

Message: 4 of 9

Markus <bhr3@gmx.de> wrote in message <ef4d07b.1@webcrossing.raydaftYaTP>...
> Obviously there are no 30 seconds of sound saved in that file, i.e.
> vector y is less than 30*Fs elements long.
>
> Markus
 hello all,
I had also received the same error in one of my programs. the code runs as follows:

function y=allow(p)
 
syms p
v=p(1:3);
t=p(4);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

load actvar

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if t == 0
    U_1(1:8,1)=zeros(8,1);
    t_1=-T;
    tim(1)=0;
    count=1;
else
    load alloc
end
U_2=U_1;

%%%ASSIGNMENT OF VALUES%%%%
BB=G

ud = zeros(8,1);

Wu=(diag([1,1,1,1,25,25,25,25]))
Wv=diag([100,100,100])

umin_act=[ -5 -5 -5 -5 -8 -8 -8 -8]'; %%%value in degrees
umax_act=-umin_act;

ratelb=[-15 -15 -15 -15 -15 -15 -15 -15]'; %%%value in degrees/second
rateub=-ratelb; %%%value in degrees/second


    imax = 500; % Heuristic value
% [k,m] = size(B);
    tol = 1e-8;
    gam = 1e3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
if t_1+T-0.000001 <= t
   
    tic;

 umin=max(Ulower_act,U_1+ratelb*T)
 umax=min(Uupper_act,U_1+rateub*T)
 

    

   u=ip_alloc(BB,v,umin,umax,Wv,Wu,ud,gam,tol,imax)
                                    
    %%UPDATION%%
    U_1(1:8,1)=u;
% U_1(9,1)=gama;
    t_1=t_1+T;
    tim(count)=toc;
    count=count+1;
    
    
elseif t_1>t
    u=U_2(1:8);
else
    u=U_1(1:8);
end

y(1:8,1)=u

save alloc U_1 U_2 t_1 tim count



%%%ALLOCATION ALGORITHM

function [u] = ip_alloc(B,v,umin,umax,Wv,Wu,ud,gam,tol,imax)

.............................

%%%%%%%%%%%%%%%%%%

the program, when run, gives the error "index exceeds matrix dimensions" at the line
v=p(1:3); itself. can anyone help me to overcome this problem? this is an urgent requirement.

Anwesha

Subject: Error - Index exceeds matrix dimensions..?

From: Jos

Date: 11 Dec, 2008 07:22:05

Message: 5 of 9

"Anwesha " <majantali.sarkar@gmail.com> wrote in message <ghqecg$9mf$1@fred.mathworks.com>...
...
> hello all,
> I had also received the same error in one of my programs. the code runs as follows:
>
> function y=allow(p)
>
> syms p
> v=p(1:3);
...
> the program, when run, gives the error "index exceeds matrix dimensions" at the line
> v=p(1:3); itself. can anyone help me to overcome this problem? this is an urgent requirement.
>
Dear Anwesha,

Apparently, the variable p does not have enough elements, so extracting the first three of them fails. This could occur if you call the function with an improper argument like in
"allow(2)" or "allow([1 2])". So, check your call to this function.

hth
Jos

Subject: Error - Index exceeds matrix dimensions..?

From: Steven Lord

Date: 11 Dec, 2008 15:28:26

Message: 6 of 9


"Anwesha " <majantali.sarkar@gmail.com> wrote in message
news:ghqecg$9mf$1@fred.mathworks.com...
> Markus <bhr3@gmx.de> wrote in message
> <ef4d07b.1@webcrossing.raydaftYaTP>...
>> Obviously there are no 30 seconds of sound saved in that file, i.e.
>> vector y is less than 30*Fs elements long.
>>
>> Markus
> hello all,
> I had also received the same error in one of my programs. the code runs as
> follows:
>
> function y=allow(p)
>
> syms p

This line overwrites the input argument p with a 1-by-1 sym object p.
That's why the next line of your code fails.

If instead you want to convert your input argument p into a sym object, use:

p = sym(p);

> v=p(1:3);
> t=p(4);

*snip*

--
Steve Lord
slord@mathworks.com

Subject: Error - Index exceeds matrix dimensions..?

From: Hemanshi

Date: 22 Feb, 2011 17:58:06

Message: 7 of 9

I could not find any such parameter mismatch in my code but I am also getting the same error of "Index exceeding Matrix dimensions". Please help.

% --- Executes just before result is made visible.
function result_OpeningFcn(hObject, eventdata, handles, varargin)

% Choose default command line output for result
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

 set(handles.txt_1Name,'string',varargin(1));
 set(handles.txt_1Score,'string',varargin(2));
set(handles.txt_2Name,'string',varargin(3));
 set(handles.txt_2Score,'string',varargin(4));
set(handles.txt_3Name,'string',varargin(5));
 set(handles.txt_3Score,'string',varargin(6));

% --- Outputs from this function are returned to the command line.
function varargout = result_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;


% --- Executes on button press in bt_Ok.
function bt_Ok_Callback(hObject, eventdata, handles)
delete(gcf);

Subject: Error - Index exceeds matrix dimensions..?

From: Mohsin Tiwana

Date: 10 Jun, 2011 05:22:02

Message: 8 of 9

your .wav file which you take in "fname1 = [name '.wav'];" is too small. If you just take a bigger file (more samples), it would solve the problem



John <ruffryder6669990@aol.com> wrote in message <ef4d07b.-1@webcrossing.raydaftYaTP>...
> Hi there, can anyone tell me what is wrong with my short piece of
> code:
>
> name = input('Please enter name of wav file to be processed
> (noextension): ','s');
> fname1 = [name '.wav'];
> [y Fs] = wavread(fname1);
> x = y([1:(30*Fs)]);
> wavwrite(x,Fs,'excerpt2.wav')
> Freq_Response = fft(x);
> Magnitude = abs(Freq_Response);
> Power = Freq_Response.*conj(Freq_Response);
> Display_Freq = fftshift(Power);
> Display_Freq2 = fftshift(Magnitude);
> plot(Display_Freq2);
>
> It returns the error message:
>
> ??? Error using ==> run
> Index exceeds matrix dimensions.
>
> I'm pretty sure it's something wrong with this line: x =
> y([1:(30*Fs)]); ..But I really don't know what... Thanks for any
> help!

Subject: Error - Index exceeds matrix dimensions..?

From: maida

Date: 12 Feb, 2014 17:40:55

Message: 9 of 9

[ m, n ] = size( Mtr );

if isscalar(BorderDistance)
    Tmp = zeros(size(Mtr));
    Tmp( (BorderDistance + 1):(m - BorderDistance), (BorderDistance + 1):(n - BorderDistance) ) = 1;
else
    Tmp = BorderDistance;
end

MtrTmp = Mtr;
Mtr = Mtr.*Tmp;
MxMtr = zeros(size(Mtr));

% calculate system of neighboors pixels
if isscalar(NBHOOD)
    NBHOOD = fspecial('disk', NBHOOD) > 0;
    N = sum(NBHOOD(:));
else
    N = sum(NBHOOD(:));
end

local_mxm = ordfilt2( Mtr, N, NBHOOD );
local_second_value = ordfilt2( Mtr, N-1, NBHOOD );

%------------------- Find thresh ---------------------%
switch ThreshType
    case 'percent'
        T = HarrisThresh*max(local_mxm(:));
    case 'const'
        T = HarrisThresh;
end
  

% indexes of strict local maximums, threshed and filterd for distance from
% borders
ind = find( (Mtr == local_mxm) & (local_second_value ~= local_mxm) & ( Mtr >= T ) );

% MxMtr(ind) = Mtr(ind);
ind = ind(:);
%[ row, clmn ] = ind2sub( [ m, n ], ind );

% defining sub-pixel accuracy
%----------------- Derivative masks ------------------%
dFdx = [ 0 0 0; -1 0 1; 0 0 0];
dFdy = [ 0 -1 0; 0 0 0; 0 1 0 ];
d2Fdx2 = [ 0 0 0; 1 -2 1; 0 0 0 ];
d2Fdy2 = [ 0 1 0; 0 -2 0; 0 1 0 ];
d2Fdxdy = [ 1 0 -1; 0 0 0; -1 0 -1 ]/4;

%-------------------- Derivatives ---------------------%
Fx = imfilter( MtrTmp, dFdx, 'same' );
Fy = imfilter( MtrTmp, dFdy, 'same' );
Fxx = imfilter( MtrTmp, d2Fdx2, 'same' );
Fyy = imfilter( MtrTmp, d2Fdy2, 'same' );
Fxy = imfilter( MtrTmp, d2Fdxdy, 'same' );

%----------- Column sub-pixel accuracy (SPA) ----------%
% formula is taken from MOP paper ( multiscale oriented patches )
ind = ind(( Fxx(ind).*Fyy(ind)-(Fxy(ind)).^2 ) ~= 0);
ClmnDeltaX = (Fx(ind).*Fyy(ind)-Fxy(ind).*Fy(ind))./( Fxx(ind).*Fyy(ind)-(Fxy(ind)).^2 );

%-------------- Row sub-pixel accuracy ----------------%
RowDeltaY = (Fy(ind).*Fxx(ind)-Fxy(ind).*Fx(ind))./( Fxx(ind).*Fyy(ind)-(Fxy(ind)).^2 );

%---- Removing pixels, that can't be approximated -----%
ind2 = find( abs(RowDeltaY)<= 1 & abs(ClmnDeltaX)<= 1 );
ind = ind( ind2 ); [ row, clmn ] = ind2sub( [ m, n ], ind );
rowSPA = row - RowDeltaY( ind2 ); clmnSPA = clmn - ClmnDeltaX( ind2 ); MxMtr(ind) = Mtr(ind);

SOMEWAT SIMILAR ERROR:
??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> Findlclmxm at 83
rowSPA = row - RowDeltaY( ind2 ); clmnSPA = clmn - ClmnDeltaX( ind2 ); MxMtr(ind) = Mtr(ind);
Error in ==> harrislpls at 78
     [ row, clmn, rowSPA, clmnSPA, MxMtr ] = Findlclmxm(HrF, NBHOOD, BorderDistance, ThreshType, HarrisThresh );

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us