필터 지우기
필터 지우기

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 CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by