Replace values in large matrix using If else
Ältere Kommentare anzeigen
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?
Antworten (1)
Fangjun Jiang
am 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 Kommentar
Jan
am 2 Nov. 2011
You can omit index3 by: d2 = zeros(size(d)); d2(index1)=-1; d2(index2)=1;
Kategorien
Mehr zu Function Replacement finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!