필터 지우기
필터 지우기

Attempted to access x(2); index out of bounds because numel(x)=1. But I'm using a matrix?

조회 수: 9 (최근 30일)
I'm just trying to execute a simple for loop, but I keep getting this error "Attempted to access x(2); index out of bounds because numel(x)=1.
Error in Quiz (line 11) x = x(i)" I don't understand what the error means. Any help would be appreciated!
x = [22.5 45 67.5 90]
for i=1:4
x = x(i)
a = a(x)
c = c(x)
alpha = alpha(x)
mu(a,c)
end

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 4일
편집: Azzi Abdelmalek 2013년 5월 4일
After one itteration
for i=1:4
x = x(i)
the length of x becomes equal to 1, then x(2) does not exist

추가 답변 (3개)

Iman Ansari
Iman Ansari 2013년 5월 4일
Hi.
You change your x in first loop :
x = x(i) ====> x=22.5
after this x became a number.
  댓글 수: 5
Pradeep Kumar R
Pradeep Kumar R 2016년 2월 25일
what should i do if i get the same error while using a if loop inside a for to plot a wave
Valentina Marincevic Petracic
Valentina Marincevic Petracic 2017년 1월 5일
편집: Stephen23 2017년 1월 5일
same question:
function [QRS] = AF2(EKG)
QRS=zeros(1,8191);
a=max(EKG);
Xth=0.4*a; %amplitude threshold
Y0=zeros(1,8191);
Y1=zeros(1,8191);
Y2=zeros(1,8191);
for n=1:8191
if (EKG(n)>0)
Y0=EKG(n);
elseif (EKG(n)<0)
Y0=-EKG(n);
end
end
%NP filtar:
for k=1:8191
y=Y0(k);
if ( y>= Xth)
Y1(k)=y;
else
Y1(k)=Xth;
end
end
%prva derivacija:
for n=2:8190
Y2= Y1(n+1)- Y1(n-1);
end
%detekcija qrs-a:
for i=0: 8191
if((Y2(i))>0.7)
QRS(i)=1;
end
end
end

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


Aaina
Aaina 2018년 8월 7일
How can I solve this problem?
Attempted to access C(38,1); index out of bounds because size(C)=[37,38].
Error in Without_DG (line 94) if ((C(f,i)==-1)&&(k==1));
%% MATLAB Program
k=1;
for i=1:no
if ((C(f,i)==-1)&&(k==1));
f=i;
g(j,e)=i;
e=e+1;
k=3;
end
end
  댓글 수: 3
Aaina
Aaina 2018년 8월 7일
편집: Aaina 2018년 8월 7일
Alright.... Thank you so much.... the input data is correct, but the code was incorrect, i tried to change the data by using the same code which need to access different network of distribution system... which from radial system into mesh system which the network more complex
Aaina
Aaina 2018년 8월 7일
I want the code can access mesh system by just adding the mesh data, but it seems doesnt work

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


deeba naqvi
deeba naqvi 2020년 10월 15일
Even I am getting the same error..plz some body help.....The programm code is.....
lb = [0,0,0,-inf];
Aeq = [1 1 1 0];
beq = 1;
x0 = [0.25 0.25 0.25 8];
fun = @(x) -x(4);
A = [];
b = [];
ub = [];
nonlinear = @Alteredplay2;
nonlcon = nonlinear(x);
[X, FVAL] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon)
function [C, Ceq] = Alteredplay2(x)
%x0 = [0.25 0.25 0.25 2];
C(1)= x(4)-((1-(5.8/8))^(0.5)*(0.1/8)^(0.5)*(1-(4.4/8))^(0.5)*(1.7/8)^(0.5))^x(1)*((1-(2/8))^(0.5)*(2.9/8)^(0.5)*(1-(1.4/8))^(0.5)*(5.8/8)^(0.5))^x(2)*((1-(3.4/8))^(0.5)*(0.1/8)^(0.5)*(1-(5.2/8))^(0.5)*(2.7/8)^(0.5))^x(3);
C(2)= x(4)-((1-(6.1/8))^(0.5)*(0.6/8)^(0.5)*(1-(3.8/8))^(0.5)*(1.7/8)^(0.5))^x(1)*((1-(2.4/8))^(0.5)*(3.1/8)^(0.5)*(1-(1.3/8))^(0.5)*(5.6/8)^(0.5))^x(2)*((1-(7.1/8))^(0.5)*(0.3/8)^(0.5)*(1-(3.6/8))^(0.5)*(0.8/8)^(0.5))^x(3);
Ceq= [];
end
and the error is....
Attempted to access x(4); index out of bounds because
numel(x)=2.
Error in Alteredplay2 (line 3)
C(1)=
x(4)-((1-(5.8/8))^(0.5)*(0.1/8)^(0.5)*(1-(4.4/8))^(0.5)*(1.7/8)^(0.5))^x(1)*((1-(2/8))^(0.5)*(2.9/8)^(0.5)*(1-(1.4/8))^(0.5)*(5.8/8)^(0.5))^x(2)*((1-(3.4/8))^(0.5)*(0.1/8)^(0.5)*(1-(5.2/8))^(0.
Error in ExceptPlay2Altered (line 10)
nonlcon = nonlinear(x);

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by