Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Why is 0 not valid in mean fucntion?

1 vue (au cours des 30 derniers jours)
Gözde Üstün
Gözde Üstün le 21 Juin 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello,
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")
end
else
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?
  3 commentaires
the cyclist
the cyclist le 21 Juin 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 le 24 Juin 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.

Réponses (0)

Cette question est clôturée.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by