필터 지우기
필터 지우기

Find values between 50th to 75th percentile.

조회 수: 6 (최근 30일)
Pritha Pande
Pritha Pande 2017년 10월 30일
I have 80*80 matrix, from which I want to extract values which lie under 50th to 75th percentile. I want to write a code such that the new matrix now formed have data which lie under 50th to 75th percentile and other values will be shown as NaN.Something like this:
for i=1:80;
for j=1:80;
if (My_matrix(i,j)<=prctile(My_matrix(i,j),25)&(My_matrix(i,j),50)=xx;
else My_matrix(i,j)==NaN
end;
end;
end;
Where, My_matrix is 2d matrix of 80*80 size. Please correct the code i have written, or tell how i can find the values which lies between 25th to 50th percentile

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 10월 30일
편집: Andrei Bobrov 2017년 10월 30일
t = prctile(My_matrix,25) > My_matrix | prctile(My_matrix,75) < My_matrix;
out = My_matrix;
out(t) = nan;
  댓글 수: 2
Pritha Pande
Pritha Pande 2017년 10월 30일
편집: Pritha Pande 2017년 10월 30일
Thank you . Now, I have attached a file of 80*80 matrix and for this file if have applied your code like this
for i=1:80;
for j=1:80;
t(i,j) = prctile(ans(i,j),25) > ans(i,j) | prctile(ans(i,j),75) < ans(i,j);
out(i,j) = t(i,j);
out(t) = nan;
end;
end;
then output showing all the matrix value as zero. How is the mistake i am making? Please rectify.
Sachindra Dhanapala Arachchige
Sachindra Dhanapala Arachchige 2018년 5월 6일
As I understand Andrei's code outputs a logical matrix (0 and 1) which satisfies the condition given in the first line of his code. By multiplying the 'My_matrix' with 't' one could get the values within 'My_matrix' which satisfy the above condition. Try the following and see. B = My_matrix.*t;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by