Replace values in large matrix using If else
Afficher commentaires plus anciens
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?
Réponses (1)
Fangjun Jiang
le 2 Nov 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 commentaire
Jan
le 2 Nov 2011
You can omit index3 by: d2 = zeros(size(d)); d2(index1)=-1; d2(index2)=1;
Catégories
En savoir plus sur Function Replacement dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!