필터 지우기
필터 지우기

How to assign discrete values in a single matrix by considering four conditions

조회 수: 3 (최근 30일)
I have one matrix.I want to check each elements of matrix with 4 conditions (say:each element is whether come under <0.25, 0.25 to 0.5, 0.5 to 0.75,0.75 to 1) .Then want to replace that element by 0,1,2,3 based on the conditions. the conditions are listed below.
if it is < 0.25 i want to assign 0,else 0.25 to 0.5 ,i want to assign 1.if it is 0.5 to 0.75, then i want to assign 2 and if it is 0.75 to 1 then i want assign 3.
it has to be done for each element of matrix.
can anybody give an idea

채택된 답변

sixwwwwww
sixwwwwww 2013년 12월 2일
편집: sixwwwwww 2013년 12월 2일
you can do it as follows:
A = rand(10);
A(A > 0.75) = 3;
A(A > 0.5 & A < 0.75) = 2;
A(A > 0.25 & A < 0.5) = 1;
A(A < 0.25) = 0;

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 2일
A = floor(rand(10) ./ 0.25);

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by