Trapz error (ORDER contains an invalid permutation index)
6 次查看(过去 30 天)
显示 更早的评论
clear
C1 = linspace(0,1e+04,3000);
k1 = 1;
k2 = 0;
n1 = 0;
n2 = 0;
nm = 0;
D = 0;
O = 0;
gam = 1e-04.*k1;
alph = 0;
w = linspace(-5,5,3000);
for ii=1:length(C1)
for jj=1:length(w)
TA = (w(jj)+D)./(k1./2);
TB = (w(jj)-O)./(gam/2);
xa = 1-1i*TA;
xb = 1-1i*TB;
C = (2.*1i.*sqrt(C1(ii)))./(sqrt(gam).*((xa.*xb)+C1(ii)));
D = (2.*xa)./(sqrt(gam).*((xa.*xb)+C1(ii)));
MC = (abs(C)).^2;
MD = (abs(D)).^2;
Sbb = 2.*pi*(MC.*(n1+0.5)+MD.*(nm+0.5));
A = trapz(w,Sbb)./(2.*pi);
AA(ii)=A;Cum
figure(1)
plot(w,Sbb)
set(gca,'FontSize',13)
xlabel('\omega')
ylabel('S_{bb}')
%ylim([0,200])
drawnow
end
end
As stated in my title, the error:ORDER contains an invalid permutation index was returned upon compiling the code. I've searched this up and found that if I put my trapz to
trapz(w,Sbb,1)
or
trapz(w,Sbb,2)
I could remedy the problem. But it appears to not work. Can anyone assist me?
Much thanks!
0 个评论
采纳的回答
Walter Roberson
2017-11-3
You have trapz(w,Sbb) with Sbb being a scalar.
There are two trapz() syntaxes with two arguments:
trapz(X, Y)
trapz(X, dim)
The way that MATLAB determines which one is being used is it looks to see whether the second argument is a vector or not: if it is then it assumes the first syntax, but if it is a scalar (as is the case for you) then it assumes the second syntax is being used.
Your w values form a line. You should not be trying to trapz() a scalar Y against a vector of X.
I think if you investigate, you will find that you can vectorize the Sbb calculation over all w values instead of using a loop. It does make sense to trapz with a vector of Sbb.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!