Apply a conditon for each row apart in a matrix

1 visualización (últimos 30 días)
Nour BS
Nour BS el 19 de En. de 2016
Editada: Stephen23 el 19 de En. de 2016
Hello,
My problem here is: If I have for example a matrix F=[0 0.6250 1; 0.7 0 1; 0.5833 1 0] and I have a random number 'r' (between 0 and 1) for example r=0.5278. I have a condition "if F(i,j)>=r" it will return the first elements (for each row) which accept the condition, so I will get as a result the vector v=[0.6250 0.7 0.5833]. My problem here is how can I apply the condition above for each row apart in my matrix.
I am new to matalb. Any response will be greatly appreciated.

Respuesta aceptada

Stephen23
Stephen23 el 19 de En. de 2016
Editada: Stephen23 el 19 de En. de 2016
F=[0 0.6250 1; 0.7 0 1; 0.5833 1 0];
r=0.5278;
% rotate the matrix:
G = F.';
C = size(G,1);
% identify all values greater than r:
X(2:C+1,:) = G>=r;
% identify only first in each column:
Y = 0<diff(X,1,1);
Z = 1==cumsum(Y,1) & Y;
% get the values:
out = G(Z)
prints
out =
0.62500
0.70000
0.58330
  1 comentario
Nour BS
Nour BS el 19 de En. de 2016
@Stephen Cobeldick I appreciate your help very much !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by