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!