The logical indices contain a true value outside of the array bounds
조회 수: 22 (최근 30일)
이전 댓글 표시
I am trying to test the following conditions:
if intabsul == absintul && intabsur==absintur
returns the corresponding entries of the xivals and Lvals
elseif intabsul ~= absintul && intabsur~= absintur
return the corresponding entries of the xivals and Lvals
elseif intabsul == absintul && intabsur~=absintur
return the corresponding entries of the xivals and Lvals
elseif intabsul ~= absintul && intabsur==absintur
return the corresponding entries of the xivals and Lvals
else do nothing.
Here is my code:
xivals = linspace(0, 10, 10);
Lvals = linspace(2e-8, 666.7e-6, 5);
for il=1:length(Lvals);
for ixi=1:length(xivals)
%
intul(ixi, il) = trapz(yvals, uxl(:, ixi, il));
intabsul(ixi, il) = trapz(yvals, abs(uxl(:, ixi, il)));
%
intur(ixi, il) = trapz(yvals, uxr(:, ixi, il));
intabsur(ixi,il) = trapz(yvals, abs(uxr(:, ixi, il)));
%
absintul(ixi, il) = abs(trapz(yvals, uxl(:, ixi, il)));
%
absintur(ixi,il) = abs(trapz(yvals, uxr(:, ixi, il)));
end
end
And I tried:
mask1 = intabsul == absintul & intabsur == absintur;
subset_xi_1 = xivals(mask1);
subset_Lv_1 = Lvals(mask1);
But I received an error: "subset_xi_1 = xivals(mask1);
"The logical indices contain a true value outside of the array bounds".
This error is because the entries in "mask1" are not all true "1" or false "0".
It seems mask1 have to be all '1' or '0' for it to work.
Is any where to tackle this problem using "if" statement instead using this approach?
I want corresponding xivals and Lvals if: intabsul == absintul & intabsur == absintur or
intabsul - absintul< epsilon & intabsur -absintur < epsilon, where epsilon =1e-12
댓글 수: 0
채택된 답변
Fangjun Jiang
2024년 2월 14일
편집: Fangjun Jiang
2024년 2월 14일
No. The problem is about the size mis-match
a=1:3;
index=[true false true true];
a(index)
In your case, you are doing logical indexing so check the value of size(mask1) and size(xivals). They need to be same to guarantee no error like above.
댓글 수: 4
Fangjun Jiang
2024년 2월 15일
You have to figure it out yourself. There are no size info or values for those variables provided. The code can't be run.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!