Filter löschen
Filter löschen

Apply a conditon for each row apart in a matrix

1 Ansicht (letzte 30 Tage)
Nour BS
Nour BS am 19 Jan. 2016
Bearbeitet: Stephen23 am 19 Jan. 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.

Akzeptierte Antwort

Stephen23
Stephen23 am 19 Jan. 2016
Bearbeitet: Stephen23 am 19 Jan. 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 Kommentar
Nour BS
Nour BS am 19 Jan. 2016
@Stephen Cobeldick I appreciate your help very much !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by