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

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));

 Risposta accettata

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 Commenti

Ive changed it to the code below to include the values for a2 and b2 and I am still getting the same error:
Not enough input arguments.
Error in a_p (line 7)
[~,I] = min(abs(a2-e));
function value = a_p(e)
%analysing power
a2 = [4.00545E-13 8.0109E-13 1.20164E-12 1.60218E-12 2.00273E-12 2.40327E-12 2.80382E-12 3.20436E-12 3.60491E-12 4.00545E-12 4.406E-12 4.80654E-12 5.20709E-12 5.60763E-12 6.00818E-12 6.40872E-12 6.80927E-12 7.20981E-12 7.61036E-12 8.0109E-12 8.41145E-12 8.81199E-12 9.21254E-12 9.61308E-12 1.00136E-11 1.04142E-11 1.08147E-11 1.12153E-11 1.16158E-11 1.20164E-11 1.24169E-11 1.28174E-11 1.3218E-11 1.36185E-11 1.40191E-11 1.44196E-11 1.48202E-11 1.52207E-11 1.56213E-11 1.60218E-11];
b2 = [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4];
%find value closest to randomly selected energy
[~,I] = min(abs(a2-e));
c2 = a2(I);
%find corresponding analysng power to that energy value
idx = find(a2 == c2);
bidx = b2(idx);
a_p = b2(idx);
value = a_p;
end
This works for me:
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
Providing the values and calling the function:
a2 = [4.00545E-13 8.0109E-13 1.20164E-12 1.60218E-12 2.00273E-12 2.40327E-12 2.80382E-12 3.20436E-12 3.60491E-12 4.00545E-12 4.406E-12 4.80654E-12 5.20709E-12 5.60763E-12 6.00818E-12 6.40872E-12 6.80927E-12 7.20981E-12 7.61036E-12 8.0109E-12 8.41145E-12 8.81199E-12 9.21254E-12 9.61308E-12 1.00136E-11 1.04142E-11 1.08147E-11 1.12153E-11 1.16158E-11 1.20164E-11 1.24169E-11 1.28174E-11 1.3218E-11 1.36185E-11 1.40191E-11 1.44196E-11 1.48202E-11 1.52207E-11 1.56213E-11 1.60218E-11];
b2 = [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4];
e = 42;
val = a_p(e,a2,b2)
producing:
val =
0.4
Did you also give it value for ‘e’? If so, you didn’t post that.
Yes it works now, e is assigned randomly via a different functions, thanks for the help
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by