Array not positive real value?
조회 수: 1(최근 30일)
Hello, I am having trouble plotting this data. I have the code below and I keep getting an error regarding "Array indices must be positive
integers or logical values."
fun = 1-(nu/2)*i*sin(x)-nu^2*sin(x/2)^2 -nu*sin(x/2)^2- nu/2*1i*sin(x)+(nu*(nu-1)/4)*(1-2*exp(-1i*x)+exp(-1i*2*x));
R = matlabFunction(real(fun), 'vars', x);
I = matlabFunction(imag(fun), 'vars', x);
range = [0:.01:pi];
for i = 1:length(range)-1
j = i*.01;
z(1,i+1) = abs(fun(j)); %sqrt(R(j)^2+I(j)^2);
Any help would be apprecaited. Also, the commented out code is just a different method I was using earlier that does the same as the abs()
Athul Prakash 2020년 11월 12일
As others have pointed out, this error message typically occurs when you're indexing an array with incompatible values (usually decimals, negatives or non-numeric types).
There seems to be a lot of indexing in the code attached; could you post the full error message, including the line where the error has occured?
At first glace, I'm not sure that 'fun' got assigned properly, there could be a bug. You may check that 'fun' works as expected before invoking 'fun(j)' later.