MATLAB Answers

Why is 0 not valid in mean fucntion?

1 view (last 30 days)
Gözde Üstün
Gözde Üstün on 21 Jun 2020
Commented: Devineni Aslesha on 24 Jun 2020
I have this function:
function [coin, I,evAlice,evBob] = CH_(sigma_x,sigma_z)
ev1_of_alice = sigma_x;
ev2_of_alice = sigma_z;
ev1_of_bob = sigma_x+sigma_z;
ev2_of_bob = sigma_x-sigma_z;
S = + mean(coin(ev1_of_alice,ev1_of_bob)) ...
- mean(coin(ev1_of_alice,ev2_of_bob)) ...
+ mean(coin(ev2_of_alice,ev1_of_bob)) ...
+ mean(coin(ev2_of_alice,ev2_of_bob));
if ~isnan(S)
fprintf("S = " + S + "\n");
if abs(S) > 2
fprintf("V! (|S|>2)\n")
fprintf("Not enough data to determine S\n")
But when coin has "0" value like that coin (1,0) or (0,1) I have this error:
Index in position 1(2) is invalid. Array indices must be positive integers or logical values.
why I am getting that how can I fixed it?


the cyclist
the cyclist on 21 Jun 2020
Can you give an example of calling this function, that gives that error?
the cyclist
the cyclist on 21 Jun 2020
Oh, also, this is confusing, because you output coin like a variable, but you also are calling it as a function (it seems). I think you might have a more fundamental problem with the code.
Devineni Aslesha
Devineni Aslesha on 24 Jun 2020
I am assuming that the coin is other nested function defined in CH_. function. Using the same name for variable and nested function is not supported in nested functions. Refer this link for more information.
But it seems that the coin is considered as an array from the above error. It would be helpful if you provide the entire code and give an example of calling CH_ function to replicate the error.

Sign in to comment.

Answers (0)




Community Treasure Hunt

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

Start Hunting!