Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Creating a matrix based on information in a vector and another matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Suppose I have a vector of success probabilities, for example:
p = [0.5,0.25,0.75]
I also have a matrix of outcomes, o, which has the same number of columns as p, containing "0's" (failure) and "1's" (success):
o = [1,0,1
0,0,0]
What I wish to obtain is the following matrix:
m = [p(1,1), 1-p(1,2), p(1,3)
1-p(1,1), 1-p(1,2), 1-p(1,3)]
So, to clarify, 1's in o result in a value equal to the corresponding value in p, while 0's in o lead to 1 minus the corresponding value in p.
What is the most efficient way to obtain m?
2 comentarios
Respuestas (1)
Andrei Bobrov
el 5 de Jul. de 2017
Editada: Andrei Bobrov
el 5 de Jul. de 2017
For MARLAB >= R2016b
out = ~o - p;
out(o>0) = -out(o>0);
MATLAB <= R2016a
out = bsxfun(@minus,~o,p);
out = out.*(1-o*2);
4 comentarios
Andrei Bobrov
el 5 de Jul. de 2017
Editada: Andrei Bobrov
el 5 de Jul. de 2017
As you please. Accept this answer or.. ?
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!