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

채택된 답변

Fangjun Jiang
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)
The logical indices contain a true value outside of the array bounds.
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
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.
University
University 2024년 2월 15일
Hi Fangjun. I have attached the data.
%
load('sol_active_flow_varinying_xiL.mat')
xi=xivals;
L =Lvals;
intabsul = intabsul;
intabsur =intabsur;
absintul =absintul;
absintur =absintur;
%% This is where I having an issue
test1 = intabsul == absintul & intabsur == absintur;
subset_xi_1 = xivals(test1);
subset_Lv_1 = Lvals(test1);
test2 = intabsul ~= absintul & intabsur ~= absintur;
subset_xi_2 = xivals(test2);
subset_Lv_2 = Lvals(test2);
%
test3 = intabsul ==absintul & intabsur ~= absintur;
subset_xi_3 = xivals(test3);
subset_Lv_3 = Lvals(test3);
%
test4 = intabsul ~= absintul & intabsur == absintur;
subset_xi_4 = xivals(test4);
subset_Lv_4 = Lvals(test4);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by