Filter löschen
Filter löschen

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

19 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 14 Feb. 2024
Bearbeitet: Fangjun Jiang am 14 Feb. 2024
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 Kommentare
Fangjun Jiang
Fangjun Jiang am 15 Feb. 2024
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 am 15 Feb. 2024
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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by