Error with find Function in MATLAB: "Incorrect number or types of inputs or outputs"
113 次查看(过去 30 天)
显示 更早的评论
Hello,
I am encountering an error in MATLAB when using the find function in my code. The error message is:
Error using find Incorrect number or types of inputs or outputs for function 'find'.
The error occurs in the following function:
load(MyData.m)
function SNR_matrix = Compute_SNR(N, numNodes, Devices,A,zeta_m_n,h0, distances,alpha,RIS_elements,arg1,arg2,Theta_node,P_v,Noise_up)
% SNR_matrix = zeros(N, numNodes, Devices);
SNR_matrix = optimexpr(N, numNodes, Devices);
for v = 1:Devices
for sb = 1:N
for node = 1:numNodes
% Find the assigned node for subtask sb of vehicle v
assigned_node = find(A(sb, :, v), 1);
% Find the covering UAV for the vehicle
covering_uav = find(zeta_m_n(v, :), 1);
if assigned_node == covering_uav
% Direct communication
SNR = sqrt(h0 * distances(v, covering_uav)^(-alpha));
SNR_matrix(sb, assigned_node, v) = (P_v*norm(SNR)^2)/Noise_up;
else
% Indirect communication through RIS
% Extract channel gain from vehicle to covering UAV
channel_gains_vehicle_to_covering = zeros(RIS_elements, 1);
for k = 1:RIS_elements
channel_gains_vehicle_to_covering(k) = arg1(v, covering_uav, k);
end
% Extract channel gain from covering UAV to assigned node
arg2_covering_to_assigned = zeros(RIS_elements, 1);
for k = 1:RIS_elements
arg2_covering_to_assigned(k) = arg2(covering_uav, assigned_node, k);
end
h_m_to_n_prime_RIS_phase_shifted = Theta_node{covering_uav} * channel_gains_vehicle_to_covering;
effective_channel = h_m_to_n_prime_RIS_phase_shifted .* arg2_covering_to_assigned;
effective_power = norm(effective_channel)^2;
% Calculate SNR
SNR = P_v * effective_power / Noise_up;
SNR_matrix(sb, assigned_node, v) = SNR;
end
end
end
end
end
and ''A'' is my optimization variable
A = optimvar('A', N, NumNodes, Devices, 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
How can I resolve this error? I have used fcn2optimexpr but the SNR expression becomes non-linear.
Is there a solution to avoid using find and keep the SNR linear?
Any Help will be appreciated.
Thanks in advance!
9 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!