フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by