Azzera filtri
Azzera filtri

Error with find Function in MATLAB: "Incorrect number or types of inputs or outputs"

113 visualizzazioni (ultimi 30 giorni)
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);
Unrecognized function or variable 'N'.
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 Commenti
Torsten
Torsten il 11 Ago 2024 alle 0:47
Modificato: Torsten il 11 Ago 2024 alle 12:10
I doubt that the error message stems from the part of the code you posted.
And I wonder why you make life difficult for yourself: you relate constraint (m,n,k) with array index (n,k,m). Doesn't it confuse you ?

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 10 Ago 2024 alle 0:03

Categorie

Scopri di più su Problem-Based Optimization Setup in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by