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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/353444/image.png)
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!
0 个评论
回答(1 个)
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 个评论
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!