Brace indexing is not supported for variables of this type. Error in test22>paretoset (line 110) soln = horzcat(varargin{1}{i}, cell2mat(varargin(2:end)));
1 次查看(过去 30 天)
显示 更早的评论
KIndly help in resolving the error? Thank you!!
% generate sample data
comm_rates = rand(100,1)*10;
interf_powers = rand(100,1)*5;
power_consumptions = rand(100,1)*2;
spectral_efficiencies = rand(100,1)*20;
robustnesses = rand(100,1)*15;
comm_rates2 = rand(100,1)*10;
interf_powers2 = rand(100,1)*5;
power_consumptions2 = rand(100,1)*2;
spectral_efficiencies2 = rand(100,1)*20;
robustnesses2 = rand(100,1)*15;
% Truncate all arrays to the length of the shortest array
min_len = min([length(comm_rates), length(interf_powers), length(power_consumptions), length(spectral_efficiencies), length(robustnesses), ...
length(comm_rates2), length(interf_powers2), length(power_consumptions2), length(spectral_efficiencies2), length(robustnesses2)]);
comm_rates = comm_rates(1:min_len);
interf_powers = interf_powers(1:min_len);
power_consumptions = power_consumptions(1:min_len);
spectral_efficiencies = spectral_efficiencies(1:min_len);
robustnesses = robustnesses(1:min_len);
comm_rates2 = comm_rates2(1:min_len);
interf_powers2 = interf_powers2(1:min_len);
power_consumptions2 = power_consumptions2(1:min_len);
spectral_efficiencies2 = spectral_efficiencies2(1:min_len);
robustnesses2 = robustnesses2(1:min_len);
% Pareto frontier for each objective
pf1_comm = paretoset(num2cell(comm_rates), num2cell(-1*interf_powers), num2cell(power_consumptions), ...
num2cell(spectral_efficiencies), num2cell(robustnesses), 'UniformOutput', false);
pf1_intf = paretoset(-1*interf_powers, power_consumptions, spectral_efficiencies, robustnesses, comm_rates);
pf1_power = paretoset(power_consumptions, spectral_efficiencies, robustnesses, comm_rates, -1*interf_powers);
pf1_spectral = paretoset(spectral_efficiencies, robustnesses, comm_rates, -1*interf_powers, power_consumptions);
pf1_robustness = paretoset(robustnesses, comm_rates, -1*interf_powers, power_consumptions, spectral_efficiencies);
pf2_comm = paretoset(comm_rates2, -1*interf_powers2, power_consumptions2, spectral_efficiencies2, robustnesses2);
pf2_intf = paretoset(-1*interf_powers2, power_consumptions2, spectral_efficiencies2, robustnesses2, comm_rates2);
pf2_power = paretoset(power_consumptions2, spectral_efficiencies2, robustnesses2, comm_rates2, -1*interf_powers2);
pf2_spectral = paretoset(spectral_efficiencies2, robustnesses2, comm_rates2, -1*interf_powers2, power_consumptions2);
pf2_robustness = paretoset(robustnesses2, comm_rates2, -1*interf_powers2, power_consumptions2, spectral_efficiencies2);
% plot Pareto fronts
figure;
subplot(2,3,1);
plot(pf1_comm(:,1), -1*pf1_comm(:,2), 'o', pf2_comm(:,1), -1*pf2_comm(:,2), 'x');
xlabel('Communication Rate');
ylabel('Interference Power');
title('Communication Rate vs. Interference Power');
subplot(2,3,2);
plot(-1*pf1_intf(:,1), pf1_intf(:,2), 'o', -1*pf2_intf(:,1), pf2_intf(:,2), 'x');
xlabel('Interference Power');
ylabel('Power Consumption');
title('Interference Power vs. Power Consumption');
subplot(2,3,3);
plot(pf1_power(:,1), pf1_power(:,2), 'o', pf2_power(:,1), pf2_power(:,2), 'x');
xlabel('Power Consumption');
ylabel('Spectral Efficiency');
title('Power Consumption vs. Spectral Efficiency');
subplot(2,3,4);
plot(pf1_spectral(:,1), pf1_spectral(:,2), 'o', pf2_spectral(:,1), pf2_spectral(:,2), 'x');
xlabel('Spectral Efficiency');
ylabel('Robustness');
title('Spectral Efficiency vs Robustness - Multi-Objective Comparison');
subplot(2,3,5);
plot(pf1_robustness(:,1), pf1_robustness(:,2), 'o', pf2_robustness(:,1), pf2_robustness(:,2), 'x');
xlabel('Robustness');
ylabel('Communication Rate');
title('Robustness vs. Communication Rate - Multi-Objective Comparison');
subplot(2,3,6);
plot3(pf1_comm(:,1), -1*pf1_comm(:,2), pf1_intf(:,2), 'o', pf2_comm(:,1), -1*pf2_comm(:,2), pf2_intf(:,2), 'x');
xlabel('Communication Rate');
ylabel('Interference Power');
zlabel('Power Consumption');
title('3D Pareto Comparison');
grid on;
function pf = paretoset(varargin)
if nargin < 2
error('paretoset:NotEnoughInputs', ...
'At least two input arguments are required.');
end
pf = varargin{1};
for i = 1:length(pf)
for j = i+1:length(pf)
if all(pf{j} <= pf{i}) && any(pf{j} < pf{i})
pf(i) = [];
pf = paretoset(pf{:});
return
elseif all(pf{i} <= pf{j}) && any(pf{i} < pf{j})
pf(j) = [];
pf = paretoset(pf{:});
return
end
end
end
for i = 1:length(pf)
soln = horzcat(varargin{1}{i}, cell2mat(varargin(2:end)));
for j = 1:nargin-1
if all(cellfun(@(x) all(x <= soln), varargin{j})) && any(cellfun(@(x) any(x < soln), varargin{j}))
pf(i) = [];
pf = paretoset(pf{:});
return
end
end
end
end
Brace indexing is not supported for variables of this type.
Error in test22>paretoset (line 110)
soln = horzcat(varargin{1}{i}, cell2mat(varargin(2:end)));
Error in test22>paretoset (line 99)
pf = paretoset(pf{:});
Error in test22 (line 31)
pf1_comm = paretoset(num2cell(comm_rates), num2cell(-1*interf_powers), num2cell(power_consumptions), ...
0 个评论
回答(1 个)
Gokul Nath S J
2023-4-18
Hi Sanjay,
Based on your query, it seems that you are not exactly transversing through the cell array. Note that varargin{i} itself is a cell array. You don't need to explicitly mention varargin{1}{i} to specify the members of the cell. Further in the code there should be some modifications, that you must specify to make it work. The line number from 94 to 101 should be modified as suggested below,
soln = horzcat(varargin{i}, cell2mat(varargin(2:end)));
for j = 1:nargin-1
if all(cellfun(@(x) all(x <= soln), varargin)) && any(cellfun(@(x) any(x < soln), varargin))
pf(i) = [];
pf = paretoset(pf{:});
return
end
end
Further, you have to pass the arguments as cell using num2cell function from line 28 to line 36.
with regads,
Gokul Nath S J
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multiobjective Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!