Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Why is 0 not valid in mean fucntion?

1 visualizzazione (ultimi 30 giorni)
Gözde Üstün
Gözde Üstün il 21 Giu 2020
Chiuso: MATLAB Answer Bot il 20 Ago 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 Commenti
the cyclist
the cyclist il 21 Giu 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 il 24 Giu 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.

Risposte (0)

Questa domanda è chiusa.

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by