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?

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 2 de Nov. de 2011
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 comentario

Jan
Jan el 2 de Nov. de 2011
You can omit index3 by: d2 = zeros(size(d)); d2(index1)=-1; d2(index2)=1;

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 2 de Nov. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by