필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error with an empty array - Subscript indices must either be real positive integers or logicals

조회 수: 1 (최근 30일)
Hi,
I'm getting an error show bellow. The reason it's because altura_raio_direto is getting an empty array. As you can see, heights is an 90 000x1 double as well as ixy.
The code is:
for yi=1:mapa.ylength
for xi=1:mapa.xlength
d(yi,xi) = sqrt((x1-x2(yi)).^2 + (y1-y2(xi)).^2).*(60/18); % 60 metros 18 pixeis
[x, y] = bresenham(Ant.Antena_x, Ant.Antena_y, xi, yi);
ix = ismember(idx_x(:),x(:));
iy = ismember(idx_y(:),y(:));
ixy = ix & iy;
altura_raio_direto = heights(ixy(1:18:end));
% Calcular equação da reta
ca = sqrt(power(Ant.Antena_x - Movel.x(xi),2)...
+power(Ant.Antena_y - Movel.y(yi),2));
co = Ant.Altura - Movel.Altura;
dv = sqrt(power(ca, 2) + power(co,2));
m = (altura_raio_direto(length(altura_raio_direto)) - Ant.Altura)/dv;
b = Ant.Altura;
LOS = 1;
for z=1:length(altura_raio_direto)
delta_h = altura_raio_direto(z) - (m * z + b);
raio_elipsoide = sqrt(...
(z * (dv - z) * lambda)/dv...
)
if (delta_h>0) | (delta_h<0 & abs(delta_h)<0.6*raio_elipsoide)
LOS = 0;
disp('Is going to exit - NLOS');
break
end
end
if LOS == 1
disp('LOS');
At(xi,yi) = 28 + 22*log10(d(yi,xi))+20*log10(3.5) + margins + at(xi,yi);
else
disp('NLOS');
At(xi,yi) = 32.4 + 20*log10(3.5) + 3*log10(d(yi,xi))+ margins + at(xi,yi);
end
end
end
Any ideia?
Thanks!

답변 (1개)

Peter O
Peter O 2020년 8월 29일
You're subscripting a logical IXY, which will only retrieve indices that evaluate to true from HEIGHTS. Is it possible that all of the IXY indices are evaluating to false? That will return an empty vector into ALTURA_RAIO_DIRETO.
Check with
all(ixy(1:18:end) == false)
  댓글 수: 2
Oliver Lestrange
Oliver Lestrange 2020년 8월 29일
You're suggesting
altura_raio_direto = heights(all(ixy(1:18:end) == false));
right?
I get the exactly same error. ixy has true and false values as you can see in the picture below.
Peter O
Peter O 2020년 8월 29일
When you access every 18th value, are those values all false? That's what I was recommending to check with all(ixy(1:18:end) == false) (as a separate command from the array access). That statement will return a single TRUE if ALL 18th values are zeros (logical-false). If all the values are logical-false, then the altura_raio value will be empty.
Oddly, if you're getting the same empty array issue, then the all(ixy(1:18:end)==false) statement is returning false, which means that at least one value of the ixy(1:18:end) is true, to make all() return false. Then you get the empty array issue again because you're trying to access heights(logical(0)), which is empty. I think that means you should have at least one logical true in the index list to heights, but that doesn't seem to be what is happening.
I'm fairly sure it's something in the indexing to heights, where everything is turning into logical zeros.
As a side note, MATLAB's idiomatic way to access the final element in an array is to use the 'end' keyword, so the command causing the error could be written as:
m = (altura_raio_direto(end) - Ant.Altura)/dv;

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by