how to compare each element of matrix?

here...i taken some variable as t ,value is 4(t=4),and f is a 4x4 matrix.. f=[1 2 3 4; 2 3 4 5 ; 5 6 7 8 ; 1 2 3 5].. how to compare the each element of matrix with T?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 1월 10일
편집: Andrei Bobrov 2013년 1월 10일

0 개 추천

t = 4;
f = [1 2 3 4; 2 3 4 5 ; 5 6 7 8 ; 1 2 3 5];
out = abs(f - t) < eps(100)
ADD
out = f;
out(f <= t) = -4;

댓글 수: 6

Dhines
Dhines 2013년 1월 10일
편집: Andrei Bobrov 2013년 1월 10일
t=4;
f=[1 2 3 4; 2 3 4 5 ; 5 6 7 8 ; 1 2 3 5];
out = abs(f - t) < eps(100)
if (out>t)
fh=t;
else
fh=-4;
end
..for this code i getting always '-4'...can u justify it?
Andrei Bobrov
Andrei Bobrov 2013년 1월 10일
here out is logical array, only 1's and 0's ( true and false )
Dhines
Dhines 2013년 1월 10일
ok sir..want to get all value in vector form 'fh'...that is in f matrix ,the first element 1 is compare to t, then i get -4 for 2 that also -4 mean while i want to get each output of compared value with t. how to construct fh?
Andrei Bobrov
Andrei Bobrov 2013년 1월 10일
see ADD part in my answer
Dhines
Dhines 2013년 1월 10일
thank u sir..little bit doubt there in ur add part...when i get output form of fh the lowest value as represent -4 thats ok. but the greater value want to present as '4' ,there is print as only matrix value..please correct that one .
Andrei Bobrov
Andrei Bobrov 2013년 1월 10일
편집: Andrei Bobrov 2013년 1월 10일
out = t*((f > t)*2-1)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2013년 1월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by