this line of code gives error. \bn
TS = traintarg(IX); traintarg{1x240, matrix} and IX{1x300, matrix} \bn
while this line does not and works fine \bn
DiS = Distr(IX); Distr{1x300, matrix} and IX{1x300, matrix}
I am not getting why this error occurs. ASAP

 채택된 답변

Adam
Adam 2017년 3월 29일
편집: Adam 2017년 3월 29일

0 개 추천

You are indexing into an array of 240 elements in the first case, 300 elements in the second case.
You haven't told us what is in IX, but even if we assume it is just integers between 1 and 300 in some arbitrary order this clearly will give an error when you index into the first array.
So I assume IX contains at least 1 value > 240
Please give details of matrix sizes and anything else relevant after (or before) the code though, don't mix them together into some strange pseudo-code, it makes it more difficult to understand what is actually code and what is just you adding information.

댓글 수: 1

muhammad haris
muhammad haris 2017년 3월 29일
편집: muhammad haris 2017년 3월 29일
TS = traintarg(IX) \bn
traintarg is a matrix of 1x240 of some random numbers. \bn
IX is also a matrix of 1x300 of some random numbers. \bn
Here is a sample code: \bn
for d = d_min : d_max;
[DS, IX] = sort(trainpat(d,:));
TS = traintarg(IX);
DiS = Distr(IX);
lDS = length(DS);
vPos = 0 * TS;
vNeg = vPos;
i = 1;
j = 1;
while i <= lDS
k = 0;
while i + k <= lDS && DS(i) == DS(i+k)
if(TS(i+k) > 0)
vPos(j) = vPos(j) + DiS(i+k);
else
vNeg(j) = vNeg(j) + DiS(i+k);
end
k = k + 1;
end
i = i + k;
j = j + 1;
end
vNeg = vNeg(1:j-1);
vPos = vPos(1:j-1);
Error = zeros(1, j - 1);
InvError = Error;
IPos = vPos;
INeg = vNeg;
for i = 2 : length(IPos)
IPos(i) = IPos(i-1) + vPos(i);
INeg(i) = INeg(i-1) + vNeg(i);
end
Ntot = INeg(end);
Ptot = IPos(end);
for i = 1 : j - 1
Error(i) = IPos(i) + Ntot - INeg(i);
InvError(i) = INeg(i) + Ptot - IPos(i);
end
idx_of_err_min = find(Error == min(Error));
if(length(idx_of_err_min) < 1)
idx_of_err_min = 1;
end
if(length(idx_of_err_min) <1)
idx_of_err_min = idx_of_err_min;
end
idx_of_err_min = idx_of_err_min(1);
idx_of_inv_err_min = find(InvError == min(InvError));
if(length(idx_of_inv_err_min) < 1)
idx_of_inv_err_min = 1;
end
idx_of_inv_err_min = idx_of_inv_err_min(1);
if(Error(idx_of_err_min) < InvError(idx_of_inv_err_min))
T_MIN(1,d) = Error(idx_of_err_min);
T_MIN(2,d) = idx_of_err_min;
T_MIN(3,d) = -1;
else
T_MIN(1,d) = InvError(idx_of_inv_err_min);
T_MIN(2,d) = idx_of_inv_err_min;
T_MIN(3,d) = 1;
end
end

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2017년 3월 29일

편집:

2017년 3월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by