フィルターのクリア

Apply a conditon for each row apart in a matrix

1 回表示 (過去 30 日間)
Nour BS
Nour BS 2016 年 1 月 19 日
編集済み: Stephen23 2016 年 1 月 19 日
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.

採用された回答

Stephen23
Stephen23 2016 年 1 月 19 日
編集済み: Stephen23 2016 年 1 月 19 日
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 件のコメント
Nour BS
Nour BS 2016 年 1 月 19 日
@Stephen Cobeldick I appreciate your help very much !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by