How do I fix this error? Not enough input arguments.

2 vues (au cours des 30 derniers jours)
James Bagnall
James Bagnall le 24 Août 2019
Commenté : Star Strider le 24 Août 2019
Im running this function:
function value = a_p(e)
%analysing power
a2 = [ ];
b2 = [ ];
%find value closest to randomly selected energy, e
[~,I] = min(abs(a2-e));
c2 = a2(I);
%find corresponding analysing power to that energy value
idx = find(a2 == c2);
bidx = b2(idx);
a_p = b2(idx);
value = a_p;
end
where a2 and b2 is just an array of data, I keep recieving the same error:
Not enough input arguments
Error in a_p (line 7)
[~,I] = min(abs(a2-e));

Réponse acceptée

Star Strider
Star Strider le 24 Août 2019
Your ‘a_p’ function has no idea what ‘a2’ and ‘b2’ are because you have not shared those with them.
Try this:
function value = a_p(e,a2,b2)
%analysing power
%find value closest to randomly selected energy, e
[~,I] = min(abs(a2-e));
c2 = a2(I);
%find corresponding analysing power to that energy value
idx = find(a2 == c2);
bidx = b2(idx);
a_p = b2(idx);
value = a_p;
end
Change your calls to ‘a_p’ to include the extra arguments. Note that your find call requires that ‘a2’ exactly equals ‘c2’, and with integers that may work. However with floating-point operations that may not be true, even if they appear to be equal in the format you are viewing them.
  4 commentaires
James Bagnall
James Bagnall le 24 Août 2019
Yes it works now, e is assigned randomly via a different functions, thanks for the help
Star Strider
Star Strider le 24 Août 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Computational Geometry dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by