How can I solve this error "Array indices must be positive integers or logical values." and make a condition to fix it as index?

2 views (last 30 days)
I want make the condition in the line 40th somthing like ,,,, if mindistD > maxrange^2 and mindistD<maxrangeD2 and then fix it in last line of code such as r_DxU = dist_D_UE( condition), but I couldn't find a way, I would appreciate any help
NumDrone=2; % Number of Drone Nodes
NumUEs=50; % Number of gound user Nodes
ro=1000; % Raduis of network layout
center=[0 0]; % Center of network layout circle
h_uav=100; % hieght of Drone Nodes
maxrange=200; % Maximum range of coverage area for Drone Nodes
maxrange1=1000; % maximum range of coverage area for Ground Node (gNB)
maxrangeD2=250; % second coverage range for Drone Nodes
PosgNB_x = (0).';
PosgNB_y = (0).';
PosgNB = [PosgNB_x,PosgNB_y];%Ground Node (gNB)
theta_Drone=2*pi*(rand(NumDrone,1)); % distributed random number of Drone Nodes
g = 0.5 * ro + 0.5 * ro * rand(NumDrone,1); % let the drones deployed away from the center of circle network layout
PosDrone_x=center(1)+g.*cos(theta_Drone); %
PosDrone = [PosDrone_x ,PosDrone_y];
theta1 = rand(NumUEs, 1) * 2*pi; % distributed random number of Users
r1 = ro * sqrt(rand(NumUEs, 1));
PosUE_x = r1 .* cos(theta1(:)) + center(:,1);
PosUE_y = r1 .* sin(theta1(:)) + center(:,2);
PosUE = [PosUE_x,PosUE_y];
PosUAV3D = [PosDrone, h_uav * ones(NumDrone,1)]; % 3D Drone Nodes Positions
PosUE3D = [PosUE, zeros(NumUEs,1)];
dist_D_UE = sum((permute(PosUE3D,[1 3 2]) - permute(PosUAV3D,[3 1 2])).^2,3); % Distance between Drone Nodes and its ground Users
dist_gNB_UE = (PosUE(:,1)-PosgNB_x.').^2 + (PosUE(:,2)-PosgNB_x.').^2; % Distance between Ground Node and its ground Users
dist_gNB_D = hypot(PosDrone_x-PosgNB_x(1,:).', PosDrone_y-PosgNB_y(1,:).'); % Distance between Ground Node and Drone Nodes
[mindistD, assigned_BS] = min(dist_D_UE,[],2); % assigned users to the nearest Drone Nodes
[mindistgNB, assigned_BS1] = min(dist_gNB_UE,[],2); % assigned users to the nearest Ground Node
inrange = mindistD <= maxrange^2; % Condition to make the Drone Nodes associated only the users that located around the Drone Node with 200m
inrangegNB = ~inrange; % Condition to make the Gound Nodes associated the users that located out of the coverage range of Drone Nodes
% Here I am trying to let the Drone Node to consider the users that located
% between 200m and 250m as interfered users
inrange2=mindistD<= maxrangeD2^2;
%if mindistD > maxrange^2 & mindistD<maxrangeD2
% outrangeD=DORange_I;
%inrangegNB= mindistgNB <= maxrange1^2 | mindistD <= maxrange^2; % interfering dist of DxU
r_B0D0 =dist_gNB_D; % distance between Ground Node and Drone Nodes
r_BxU = dist_gNB_UE(inrange); % distance between interfering Ground Node and user
r_B0U = dist_gNB_UE(inrangegNB); % distance between serving Ground Node and user
r_D0U = dist_D_UE(inrange); % distance between the serving drone Node and users
r_DxU = dist_D_UE(X)-dist_D_UE(Y); % distance between interfering Drone Node and user

Accepted Answer

Kevin Holly
Kevin Holly on 15 Mar 2022
Edited: Kevin Holly on 15 Mar 2022
mindistD > maxrange^2 and mindistD<maxrangeD2 gave no results. Is it suppose to be mindistD < maxrange^2 and mindistD>maxrangeD2?
If so, you could do the following:
dist_D_UE(mindistD < maxrange^2 & mindistD>maxrangeD2,1)
Note, there are two columns in dist_D_UE
  1 Comment
omar th
omar th on 15 Mar 2022
Thank you for your reply, But I want to consider only the users that are located between these ranges 200m and 250 can be interfered by the Drone Node Not consider all users out of 200 can be interfered by this Drone Node as showed in the figure. I hope this figure let you get my point, please don't hesitate to ask me if you need any clarification

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by