Attempted to access x(2); index out of bounds because numel(x)=1. But I'm using a matrix?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Azzi Abdelmalek
il 4 Mag 2013
Modificato: Azzi Abdelmalek
il 4 Mag 2013
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 Commenti
Più risposte (3)
Iman Ansari
il 4 Mag 2013
Hi.
You change your x in first loop :
x = x(i) ====> x=22.5
after this x became a number.
5 Commenti
Pradeep Kumar R
il 25 Feb 2016
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
il 5 Gen 2017
Modificato: Stephen23
il 5 Gen 2017
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
il 7 Ago 2018
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 Commenti
Aaina
il 7 Ago 2018
Modificato: Aaina
il 7 Ago 2018
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
il 7 Ago 2018
I want the code can access mesh system by just adding the mesh data, but it seems doesnt work
deeba naqvi
il 15 Ott 2020
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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!