Index in position 1 exceeds array bounds (must not exceed 1)

조회 수: 1,987 (최근 30일)
noe
noe 2018년 11월 21일
편집: Torsten 2023년 10월 11일
Hello, I'm trying to run this code (gauss elimination), but i get an error message :Index in position 1 exceeds array bounds (must not exceed 1). the error message comes from "am(in,in)=bm(in,im);". What does "Index in position 1 exceeds array bounds (must not exceed 1)" mean? and how to solve this?
Here is code :
n=3
a=[1,2,3;4,3,2;,9,8,7]
b=[3;4;2]
k=n;
for i=1:k
for j=1:k+1
if j~=k+1
am(i,j)=a(i,j);
else
am(i,j)=b(i);
end
end
end
m=n+1;
for i=1:n
for j=1:m
bm(i,j)=am(i,j)/am(i,i);
end
for k=1:n
for l=1:m
if i==k
bm(k,l)=am(k,l)-bm(i,l)*am(k,i);
end
end
end
for in=1:n
for im=1:m
am(in,im)=bm(in,im);
end
end
end
for i=1:n
c(i)=am(i,m);
end
  댓글 수: 2
Torsten
Torsten 2018년 11월 21일
The array "bm" has size (1,4) when you enter the nested for loop
for in=1:n
for im=1:m
am(in,im)=bm(in,im);
end
end
Thus for in>1, you try to access elements in "bm" that do not yet exist.
Since I did not try to understand your code, you have to solve this problem on your own.
noe
noe 2018년 11월 22일
thank you sir

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

답변 (5개)

Jan
Jan 2018년 11월 21일
편집: Jan 2018년 11월 21일
The message:
"Index in position 1 exceeds array bounds (must not exceed 1)"
seems to be very clear: The first index of an array is 2, but the array has a length of 1 in the first dimension only. Use the debugger to examine such problems:
dbstop if error
Type this in the command window and run the code again. When Matlab stops at the error, cehck the sizes of the used variables:
size(bm)
in
im
By the way, this can be simplified:
for i=1:k
for j=1:k+1
if j~=k+1
am(i,j)=a(i,j);
else
am(i,j)=b(i);
end
end
end
to:
am = [a(1:k, 1:k), b];
% Or:
am = [a, b];

Gul Rukh Khan
Gul Rukh Khan 2019년 12월 8일
Respected Sir,
I have one question in my 10x10 matrix image.
I want to compare first pixel of 10x10 matrix with the right side and bottom side element, and based on the difference whichever is greater move towards that direction.
This is bacially for Edge Detection, sir.
Can you help me accordingly. i am waiting for your prompt response. Thanks
best Regards
gul Rukh Khan
  댓글 수: 2
Jan
Jan 2019년 12월 9일
Please do not attach a new question to an existing thread. Open a new thread instead and remove this message. Thanks.

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


NOR AZIERA
NOR AZIERA 2022년 12월 14일
편집: NOR AZIERA 2022년 12월 14일
Sir...can i ask u ..how to solve this problem?
n=3; A=randn(n); A=A'*A; [V,D]=eig(A);
for i=1:n
X=outprod(V(:,i),D(i))*V'
display(X);
display(A');
end
  댓글 수: 2
Jan
Jan 2022년 12월 14일
@NOR AZIERA: Please do not post a new question in the section of answers of another question.
You have asked this in another question already, so please delete this answer.
Rahul Pandit
Rahul Pandit 2022년 12월 26일
Hi Sir
I need your help develop a code for cross correlation using the delay.
I have two 5Sec signals and i want to do the cross corelation of both the signals.
a = xlsread(signals 5sec.xls);
t1 = a(:,1); %time (Time is same for both the signal)
yR1 = a(:,2); % 1st signal
yR2 = a(:,4); % 2nd signal
% Cross Correlation
[r,lags] = xcorr(yR1,yR2);
plot(lags,r,'color','r','linewidth',1.6);
But i want to do the delay of 1 sec and then do the cross correlation using the for loop, i must to iterate the signals 1sec to 5sec for 1st signal and same thing i have to repeate in negative direction also. so i can get the neagtive and positive both the pulses.
Please help me to grow my self.

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


fatma
fatma 2022년 12월 25일
code:
Ncyc = Ncyc_primes (find (gcd (Ncyc_primes, N) ==1), 1, 'last ')
erorr:
Index in position 1 exceeds array bounds. Index must not exceed 1.
  댓글 수: 1
Jan
Jan 2022년 12월 26일
This line cuases the same error message, but has no other connection to the original error message. Most of all, it is not an answer, but a new question, I assume. So please open a new question and delete the message here. Thanks.

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


Somad
Somad 2023년 10월 11일
could someone help me please,
this is my loop:
for tdz = 1:length(t_vec)-1 %%%integrator integrates to tdx+1
for idz = 2:length(z_vec)-1 % because 1 is T_mat(1,:), bc, doesnot change, also length(x_vec) = T_mat(end,:)
CCO2v(idz, tdz+1) = ( CCO2v(idz,tdz)+ (-CCO2v(idz,tdz+1) * (uG(idz+1,tdz) - uG(idz-1,tdz))/dz - uG * (CCO2v(idz+1,tdz) - CCO2v(idz-1,tdz))/dz - aw*NCO2)*dt)/gasholdup;
CCO2l(idz, tdz+1) = (CCO2l(idz,tdz) - (uL*(CCO2l(idz-1,tdz) - CCO2l(idz+1,tdz))/dz + aw*NCO2)*dt)/liqholdup;
TGmat(idz, tdz+1) = ((-uG*(TGmat(idz+1,tdz) - TGmat(idz-1,tdz))/dz + (aw/(CCO2v(idz, tdz+1)*cp_CO2))*hg*(TLmat(idz, tdz+1)-TGmat(idz, tdz+1)))*dt + TGmat(idz,tdz))/gasholdup;
TLmat(idz, tdz+1) = ((-uL*(TLmat(idz-1,tdz) - TLmat(idz+1,tdz))/dz - aw*hg(TLmat(idz, tdz+1)-TGmat(idz, tdz+1))/(CCO2v(idz, tdz+1)*cp_CO2) - dH*NH2O - dHH2O*NH2O)*dt + TLmat(idz,tdz))/liqholdup;
end
end
the error also: Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in Absorber (line 235)
CCO2v(idz, tdz+1) = ( CCO2v(idz,tdz)+ (-CCO2v(idz,tdz+1) * (uG(idz+1,tdz) - uG(idz-1,tdz))/dz - uG * (CCO2v(idz+1,tdz) - CCO2v(idz-1,tdz))/dz - aw*NCO2)*dt)/gasholdup;
  댓글 수: 1
Torsten
Torsten 2023년 10월 11일
편집: Torsten 2023년 10월 11일
How did you initialize the 2d-array CCO2v ?
On the right-hand side of the equation
CCO2v(idz, tdz+1) = ( CCO2v(idz,tdz)+ (-CCO2v(idz,tdz+1) * (uG(idz+1,tdz) - uG(idz-1,tdz))/dz - uG * (CCO2v(idz+1,tdz) - CCO2v(idz-1,tdz))/dz - aw*NCO2)*dt)/gasholdup;
you try to access elements of CCO2v that do not yet seem to exist.
Further, the right-hand side contains CCO2v(idz,tdz+1) which you want to define by the equation. This must be wrong.

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

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by