Replace values in large matrix using If else

I am currently using dataset matrix which contains continuous data. I need to use If else to replace all the data that less than -1.53 to -1, data that more than 1.1366 to 1 and for others, it will be replce by 0. Any solution?

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 2일

0 개 추천

You could use if-else, but using index is easier and more efficient. It applies to dataset array or ordinary array. Use this example:
d=rand(8,9);
index1=d<0.3;
index2=d>0.7;
index3=and(~index1,~index2);
d(index1)=-1;
d(index2)=1;
d(index3)=0;

댓글 수: 1

Jan
Jan 2011년 11월 2일
You can omit index3 by: d2 = zeros(size(d)); d2(index1)=-1; d2(index2)=1;

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

태그

질문:

2011년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by