Azzera filtri
Azzera filtri

Apply a conditon for each row apart in a matrix

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Stephen23
Stephen23 il 19 Gen 2016
Modificato: Stephen23 il 19 Gen 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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by