In both of these functions, you only create the variable rssi_dB
if execution enters the if
statement within the loop (i.e., if xAnchorID==a && xSourceID==b
is at some point true). Clearly, this code is never executed in your A50
function. Without knowing what is in BlinkSet
it's a bit difficult to diagnose the exact problem, but this is the cause at least.
As a side note: it's not a good idea to create two separate functions to do this job when their code is almost identical. You should add an input argument to your function that allows it to do the job of both. In this particular case, all that changes is the value of xAnchorID
and xSourceID
, so you could just pass these in:
function srcToAnchorRssi(BlinkSet, xSourceID, xAnchorID)
% The rest of the function stays the same!
If you want to provide some defaults for these arguments, you can do, e.g.:
if nargin < 3 || isempty(xAnchorID), xAnchorID = 50; end
if nargin < 2 || isempty(xSourceID), xSourceID = 30; end
It's always a good idea to include an isempty
in statements of this sort, so that your function supports syntax like myFunction(myArg1, [], myArg3)
. Also note that the order of the operands to ||
is crucial; if you did if isempty(theArgument) || nargin < theArgumentNumber
and the user did not pass theArgument
, then it would error in the isempty
because theArgument
would not exist as a local variable. We can get around this by swapping the operands' order because MATLAB is smart enough to know it doesn't have to evaluate the right operand if the left operand is true
(note that this is also the case in many other programming languages).