How to resolve the "Index exceeds matrix dimensions" error ?

if true
data = getdata(vid,50,'double','cell');
for i=1:5:100
data{i}(:,:,1)=(data{i}(:,:,1))+(data{i+1}(:,:,1))+(data{i+2}(:,:,1))+ ...
(data{i+3}(:,:,1))+(data{i+4}(:,:,1))/5;
data{i}(:,:,3)=(data{i}(:,:,3))+(data{i+1}(:,:,3))+(data{i+2}(:,:,3))+...
(data{i+3}(:,:,3))+(data{i+4}(:,:,3))/5;
data{i}(:,:,2)=(data{i}(:,:,2))+(data{i+1}(:,:,2))+(data{i+2}(:,:,2))+...
(data{i+3}(:,:,2))+(data{i+4}(:,:,2))/5;
end
end
[EDITED, Jan, code formatted - Please do this by your own, thanks!]

답변 (3개)

Dishant Arora
Dishant Arora 2012년 8월 26일
dbstop if error
use this before executing,u will get an idea where exactly this error occurs

댓글 수: 9

no its not work
data = getdata(vid,50,'double','cell');
from this what i conclude is that you have 50 samples/elemesnts in cell array data. and indices in your code goes above 50 and that results in error. you should once again take look at the loop and reassign i.
@sadhna: "it's not working" is not helpful for us. Please explain all necessary details, e.g. the line which causes the error, the size of the processed array and the value of i. Finally these informations should allow you to solve the problem by your own.
??? Index exceeds matrix dimensions.
Error in ==> lol2 at 38 data{i+1}(:,:,1)=(data{i}(:,:,1)+data{i+5}(:,:,1))/2;
Ryan
Ryan 2012년 8월 27일
편집: Ryan 2012년 8월 27일
If I had to guess, data{101} through data{104} do not exist and you'll need to stop your loop sooner. What is the size of data?
if true data = getdata(vid,50,'double','cell'); for i=1:5:100 for i=1:5:50 data{i+1}(:,:,1)=(data{i}(:,:,1)+data{i+5}(:,:,1))/2; data{i+1}(:,:,2)=(data{i}(:,:,2)+data{i+5}(:,:,2))/2; data{i+1}(:,:,3)=(data{i}(:,:,3)+data{i+5}(:,:,3))/2; end
ERROR Index exceeds matrix dimensions.
Error in ==> lol2 at 38 data{i+1}(:,:,1)=(data{i}(:,:,1)+data{i+5}(:,:,1))/2;
Ok, I assume that this is the line, which causes the problem. Correct? What is the value of "i"? What is the size of "data{i}" and "data{i+5}". Come on, Sadhna, start to debug your code and show some effort to solve your problem.
i cant understand how to solve this prob ..plz help me out of this...
change the loop form 1 to 50
for i=1:5:50

댓글을 달려면 로그인하십시오.

serena dsouza
serena dsouza 2020년 8월 3일
Hi, I am getting same error in this following loop but on selected samples , even though they are of same length, Only Some of them giving error. Here, I am trying to do framing of audio signal.Can anyone help me in this.Thank you.
n=round(length(xOut)/no_frames); %find how many samples will each frame contain
P=zeros(n,no_frames);
for j=0:no_frames-1
P(:,j+1)=xOut(1+n*j:n*(j+1));
end
maryam ahmad
maryam ahmad 2021년 6월 2일
Hi i want to 3D plot of x, y anad z and for that i have table of 1000x1 (name 'Rouser1') and have 3 variables as following
x(n) = seq (n)-seq (n-1);
y(n) = seq (n-1) - seq (n-2);
z(n) = seq (n-2) - seq (n-3);
% in this seq will be the 'values of Rouser1' and Variable of Rouser1 is 'VarName1'
% so how im suppose to make a 3D plot?

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2012년 8월 26일

답변:

2021년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by