Hello ! its urgent can u please help me with this error in the MATLAB Code
Show older comments
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
Image Analyst
on 27 Oct 2014
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.
Chad Greene
on 27 Oct 2014
Jan
on 27 Oct 2014
@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.
Image Analyst
on 27 Oct 2014
"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.
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.
Image Analyst
on 28 Oct 2014
That code is not all that helpful. Just attach the m-file with the paper clip icon.
Answers (2)
Image Analyst
on 28 Oct 2014
0 votes
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!
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.
Categories
Find more on Nearest Neighbors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!