Hello ! its urgent can u please help me with this error in the MATLAB Code

function [MSD_theory, MSD_simulation, c_itr_theory, c_itr_simulation] = gATC_main( alpha, itr_cost_ratio, n_hops, no_of_simulations, adaptation_on, vineq_on, relax_on, regularization_on )
get_data % get the data required in optimization
GAMMA = diag(inv_gamma2);
z = sdpvar(N, 1);
q = sdpvar(N, N, 'full');
(line 23 :)if ~relax_on
delta = binvar(N, N, 'full');
omega = binvar(N, N, 'full');
C1 = [];
else
delta = sdpvar(N, N, 'full'); % relaxed version
omega = sdpvar(N, N, 'full');
C1 = [0<=delta<=1, 0<=omega<=1];
end
C1 = [C1 z_lb <= z <= z_ub, q >= 0];
for i = 1:N
temp = i; % store the nodes within n_hops away
for j = 1:n_hops
temp0 = temp;
for ii = temp0
temp = [temp setdiff(phy_neighbor_sets{ii},temp)];
end
end
temp2 = setdiff(set_I,temp);
if ~isempty(temp2)
C1 = [C1 delta(i,temp2)==0 omega(i,temp2)==0];
end
This is the partial program codes and the error that i m getting is
Error using gATC_main (line 23)
Not enough input arguments.

8 Comments

You forgot to paste the whole error message. You snipped out just a small part of it and forgot to include one critical part: the line of code that it errored on. What line is line #23? Please paste in ALL THE RED TEXT , not just part of it.
@Image Analyst: Line 23 seems to be marked by "(line 23 :)"
if ~relax_on
I'm in doubt, that this line can cause the posted error message.
"if ~relax_on" has no input arguments so that definitely is not causing the error and must not be line 23. So, lpsita, that's why it's important to post the complete, full error message. If you've already solved the problem, then just come back and say it's all solved. I can just delete the whole question if you want since it doesn't apply anymore, and was never stated clearly enough to be of help to anyone else.
i can post the entire program. and i really need a solution.
function [MSD_theory, MSD_simulation, c_itr_theory, c_itr_simulation] = gATC_main( alpha, itr_cost_ratio, n_hops, no_of_simulations, adaptation_on, vineq_on, relax_on, regularization_on )
get_data % get the data required in optimization
GAMMA = diag(inv_gamma2);
z = sdpvar(N, 1);
q = sdpvar(N, N, 'full');
if ~relax_on
delta = binvar(N, N, 'full');
omega = binvar(N, N, 'full');
C1 = [];
else
delta = sdpvar(N, N, 'full'); % relaxed version
omega = sdpvar(N, N, 'full');
C1 = [0<=delta<=1, 0<=omega<=1];
end
C1 = [C1 z_lb <= z <= z_ub, q >= 0];
for i = 1:N
temp = i; % store the nodes within n_hops away
for j = 1:n_hops
temp0 = temp;
for ii = temp0
temp = [temp setdiff(phy_neighbor_sets{ii},temp)];
end
end
temp2 = setdiff(set_I,temp);
if ~isempty(temp2)
C1 = [C1 delta(i,temp2)==0 omega(i,temp2)==0];
end
for j = 1:length(temp)
if shortest_path_dis(i,temp(j)) == n_hops
C1 = [C1 omega(i,temp(j))==0];
end
end
end
return
C4 = [];
for i = set_I
for j = set_I
C4 = [C4 z_lb(j)*delta(i, j) - q(i, j) <= 0];
C4 = [C4 z(j) + z_ub(j)*(delta(i, j)-1) - q(i, j) <= 0];
C4 = [C4 z_ub(j)*delta(i, j) - q(i, j) >= 0];
C4 = [C4 z(j) + z_lb(j)*(delta(i, j)-1) - q(i, j) >= 0];
end
end
C5 = [sum(GAMMA*q, 1) - 1 == 0, sum(delta, 1) - 1 >= 0];
C6 = [];
for k = set_I
for i = set_I
if all(Eta(i,:,k)==0)
C6 = [C6, omega(i, k) == 0];
else
C6 = [C6, omega(i, k) <= sum(Eta(i, :, k).*delta(i, :)) <= (N-1)*omega(i, k)];
end
end
end
cons = [C1 C4 C5 C6];
% valid inequalities
if vineq_on
C7 = [];
for k = set_I
C7 = [C7 delta(k,k) == 1];
end
for j = set_I
for k = phy_neighbor_sets{j}
for l = full_info_neighbors{k}
C7 = [C7 omega(l,k)<=delta(l,j)];
end
end
end
for k = set_I
for l = full_info_neighbors{k}
if l==k
continue;
end
C7 = [C7 omega(l,k)<=omega(l,l)];
end
end
cons = [cons C7];
end
obj = sum(z);
% cons = [cons sum(sum(omega))+f_sc <= per_itr_cost_ub*itr_cost_ratio];
cons = [cons sum(sum(omega))+f_sc <= itr_cost_ratio];
disp(' Start to solve the problem ...')
disp(' ')
% optimization
% ops = [];
% ops = sdpsettings('verbose',1,'showprogress',0,'solver','bnb','bnb.maxiter',2000); ops = sdpsettings('verbose',1,'showprogress',0,'solver','cplex');%,'cplex.diagnostics','on');
t0 = tic;
diagnostics = solvesdp(cons, obj, ops);
solution_time = toc(t0)
if diagnostics.problem
err = diagnostics.problem;
disp(' ')
disp(['Error: ' yalmiperror(err)])
return
end
% solution
omega = double(omega)
if ~relax_on | ~regularization_on % exact solution, or relaxed solution with a probability interpretation delta_opt = double(delta)
omega_opt = omega
obj = double(obj)
else
threshold_min = inf;
for i = set_I
for j = set_I
temp = abs(omega-omega(i,j));
temp = min(temp(temp>1e-5));
if threshold_min > temp
threshold_min = temp;
end
end
end
threshold_min
threshold = 1 + threshold_min;
omega_opt = zeros(size(omega));
while sum(sum(omega_opt)) < itr_cost_ratio
threshold = threshold-threshold_min;
[r_omega c_omega] = find(omega>=threshold);
for i = 1:length(r_omega)
omega_opt(r_omega(i),c_omega(i)) = 1;
if sum(sum(omega_opt)) == itr_cost_ratio
break;
end
end
end
% disp('Search for the relaxed solution...')
% diagnostics = solvesdp(cons, obj, ops);
% if diagnostics.problem
% err = diagnostics.problem;
% disp(' ')
% disp(['Error: ' yalmiperror(err)])
% disp('The way regularizing the solution is infeasible. Please try a different threshold!')
% return
% end
% delta = double(delta) % delta(delta<=0.99) = 0; % delta_opt = delta;
delta_opt = eye(N,N);
for i = set_I
for j = set_I
if omega_opt(i,j)
delta_opt(i,phy_neighbor_sets{j}) = 1;
end
end
end
threshold, omega_opt, delta_opt
end
temp = ones(N, N).*delta_opt';
info_neighbor_set_opt = cell(N,1);
for i = set_I
info_neighbor_set_opt{i} = find(temp(i,:)>0);
end
MSD_opt = itr_required(info_neighbor_set_opt, max_itr);
[omega per_itr_cost_opt] = per_itr_cost(Eta, delta_opt);
% display results/
disp('Info neighbor configurations for nodes 1 to N:')
info_neighbor_set_opt{set_I}
disp(['[per_itr_cost1, per_itr_cost2, per_itr_cost_opt]: [', ... num2str([per_itr_cost1, per_itr_cost2, per_itr_cost_opt]),' ]'])
disp(['[MSD1(end), MSD2(end), MSD_opt(end)]: [', ... num2str([MSD1(end), MSD2(end), MSD_opt(end)]),']'])
if isempty(NO_broadcast)
figure
% figure(1)
if No_of_simulations
subplot(1,2,1)
end
% plot(itrs, MSD2(itrs), '-r','linewidth', 2)
% plot(itrs, MSD_opt(itrs), '-b','linewidth',2)
plot(itrs, MSD2(itrs), '--r',itrs, MSD_opt(itrs), '-b', 'linewidth',2)
% plot(itrs, MSD_opt(itrs), '-b',...
% itrs, MSD1(itrs), ':g', itrs, MSD2(itrs), '--r','linewidth',2)
% xlabel('Iteration, $i$','interpreter','latex')
% ylabel('$MSD_{i}$ (dB) by theory','interpreter','latex')
end
MSD_theory = MSD_opt(end); % theoretical steady-state MSD
for i = itrs
if MSD_opt(i)<=0.9*MSD_theory
% c_itr_theory = i-1; % theoretical convergence iteration
c_itr_theory = (MSD_opt(1)-MSD_opt(i)) / (i-1); % % theoretical (appro.) convergence rate
break;
end
end
if ~No_of_simulations
MSD_simulation = -1; % a value of nonsense
c_itr_simulation = -1; % a value of nonsense
return
end
% Monte-Carlo simulations
disp(' ')
disp('Running Monte-Carlo simulations...')/
disp(' ')
randn('state',300)
n_itr = length(MSD2);
simu_MSD1 = zeros(No_of_simulations,n_itr);
simu_MSD2 = simu_MSD1; simu_MSD2_modified = simu_MSD1;
simu_MSD_opt = simu_MSD1;
w_TRUE = reshape(w_true,N,M);
for i = 1:No_of_simulations
if mod(i,100)==0
disp(['Simulation number: ' num2str(i)])
end
% w1 = simul_estimates(alpha, info_neighbor_set1, n_itr, adaptation_on); % call the funtion to run simulations and return estimates
% w2 = simul_estimates(alpha, info_neighbor_set2, n_itr, adaptation_on);
% w2_modified = simul_estimates3(alpha, info_neighbor_set2, n_itr, adaptation_on);
if relax_on & ~regurization_on
w3 = simul_estimates2(alpha, omega_opt, n_itr, adaptation_on);
else
w3 = simul_estimates(alpha, info_neighbor_set_opt, n_itr, adaptation_on);
end
for j = 1:n_itr
% simu_MSD1(i,j) = sum(sum((w1(:,:,j)-w_TRUE).^2))/N;
% simu_MSD2(i,j) = sum(sum((w2(:,:,j)-w_TRUE).^2))/N;
% simu_MSD2_modified(i,j) = sum(sum((w2_modified(:,:,j)-w_TRUE).^2))/N;
simu_MSD_opt(i,j) = sum(sum((w3(:,:,j)-w_TRUE).^2))/N;
end
end
% avg_simu_MSD1 = 20*log10(mean(simu_MSD1,1));
% avg_simu_MSD2 = 20*log10(mean(simu_MSD2,1));
% avg_simu_MSD2_modified = 20*log10(mean(simu_MSD2_modified,1));
avg_simu_MSD_opt = 20*log10(mean(simu_MSD_opt,1));
if isempty(NO_broadcast)
subplot(1,2,2)
% plot(1:n_itr, avg_simu_MSD1(1:n_itr), ':g','linewidth', 2),hold on
% plot(1:n_itr, avg_simu_MSD2(1:n_itr), '--r','linewidth', 2),hold on
% plot(1:n_itr, avg_simu_MSD2_modified(1:n_itr), '-.m','linewidth', 2),hold on
plot(1:n_itr, avg_simu_MSD_opt(1:n_itr), '-b','linewidth', 2)
hold on
xlabel('Iteration','interpreter','latex')
ylabel('$MSD_{i}$ (dB) from simulation','interpreter','latex')
end
% for i = itrs
% if avg_simu_MSD2(i)<=0.9*avg_simu_MSD2(end)
% % c_itr_simulation2 = i-1; % convergence time % c_itr_simulation2 = (avg_simu_MSD2(1)-avg_simu_MSD2(i)) / (i-1); % (appro.) convergence rate % break; % end % end % pause
% for i = itrs % if avg_simu_MSD2_modified(i)<=0.9*avg_simu_MSD2_modified(end) % % c_itr_simulation2_modified = i-1; % convergence time % c_itr_simulation2_modified = (avg_simu_MSD2_modified(1)-avg_simu_MSD2_modified(i)) / (i-1); % (appro.) convergence rate % break; % end % end % pause
for i = itrs
if avg_simu_MSD_opt(i)<=0.9*avg_simu_MSD_opt(end)
% c_itr_simulation = i-1; % convergence time c_itr_simulation = (avg_simu_MSD_opt(1)-avg_simu_MSD_opt(i)) / (i-1); % (appro.) convergence rate break; end end MSD_simulation = avg_simu_MSD_opt(end); % steady-state MSD of interest
and the error is
Error using gATC_main (line 23) Not enough input arguements.
Most people who post questions here "really need a solution" else they wouldn't come here unless they are being lazy!
How many arguments are you sending into the function (I'm really not going to plough through all that unformatted code to see if I can find that out!)?
Usually a "Not enough input arguments" error comes about because you are not passing enough input arguments to the function in question.
Sadly so few functions I see make use of narginchk and/or validateattributes and other useful checks to make sure of the input arguments and give appropriate error messages if the input arguments are not sufficient. e.g., theoretically this function could be called with anything from 0 to 8 arguments and the only thing that determines that it presumably needs all 8 is when a line of code happens to require each of them.
That code is not all that helpful. Just attach the m-file with the paper clip icon.

Sign in to comment.

Answers (2)

How did you run gATC_main? Attach that m-file along with the test program that you used to call it. If you just clicked the green triangle, then of course it's missing all of the arguments!
Adam
Adam on 28 Oct 2014
Edited: Adam on 28 Oct 2014
To expand a little on what I put in my comment despite my general dislike of responding to anything that claims to be "urgent"!
Line 23 is almost certainly throwing the error because it is the first line that uses any of the input arguments. In this case it uses the 7th argument.
So when the code gets to this point it requires that 7th argument (and therefore obviously the previous 6 too even though it hasn't needed to use them yet). When it can't find it you will get the error message shown.
Up until that point none of the input arguments were being used so you could call your function with any number of input arguments from 0 to 8 and it would run up until that point, in the nature of an interpreted language.
Again, this is why I always like to use things like narginchk and validateattributes to catch these things in an orderly manner rather than just on whatever line happens to require an input argument that wasn't supplied. Admittedly I never tend to use narginchk if my function has no optional arguments, but validateattributes takes care of that anyway provided I use it for each input argument which I do. Not only does it catch errors clearly and easily it also provides documentation on what the input arguments are expected to be since Matlab is not a typed language that clearly says input argument 3 should be a struct, argument 4 a double, argument 5 a string, etc etc.

Asked:

on 27 Oct 2014

Edited:

on 28 Oct 2014

Community Treasure Hunt

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

Start Hunting!