Attempted to access x(2); index out of bounds because numel(x)=1. But I'm using a matrix?
6 次查看(过去 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
0 个评论
采纳的回答
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
0 个评论
更多回答(3 个)
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
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
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
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
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
2018-8-7
I want the code can access mesh system by just adding the mesh data, but it seems doesnt work
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);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!