The logical indices contain a true value outside of the array bounds

31 ビュー (過去 30 日間)
University
University 2024 年 2 月 14 日
コメント済み: University 2024 年 2 月 15 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by