putting specific values in an array to zero
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jason
el 25 de En. de 2016
Comentada: Jason
el 25 de En. de 2016
I have an array of numbers
BIM2=
0 0 0 0 0 671 0 0 0 0 0 866 0 0 0 0 0 842 0 0
0 0 0 0 0 574 0 0 0 0 0 671 0 0 0 0 0 671 0 0
0 0 0 0 1147 622 0 0 0 0 1001 818 866 0 0 0 1208 671 0 0
0 0 598 793 0 0 0 671 659 866 0 0 0 0 488 866 0 0 0 0
0 0 610 0 0 0 0 0 439 0 0 0 0 0 683 0 0 0 0 0
0 0 647 0 0 0 0 0 1025 0 0 0 0 0 805 0 0 0 0 0
0 0 903 0 0 0 0 0 781 0 0 0 0 0 683 0 0 0 0 0
0 0 671 732 0 0 0 927 647 952 0 0 0 0 903 915 0 0 0 915
1184 732 647 598 732 818 0 0 0 0 891 683 1159 720 513 635 1025 647 879 866
0 0 0 0 452 586 0 0 0 0 0 683 0 0 0 0 0 732 0 0
0 0 0 0 110 793 0 0 0 0 0 830 0 0 0 0 0 720 0 0
0 0 0 0 244 732 0 0 0 0 0 854 0 0 0 0 0 866 0 0
0 0 0 0 940 781 0 0 0 0 757 561 879 0 0 0 866 671 0 0
0 0 0 0 1013 513 696 854 586 1196 1196 610 830 0 0 0 1123 549 769 940
0 0 561 0 0 0 0 0 439 0 0 0 0 0 598 0 0 0 0 0
0 0 622 0 0 0 0 0 659 0 0 0 0 0 757 0 0 0 0 0
0 0 818 0 0 0 0 0 732 0 0 0 0 0 708 0 0 0 0 0
0 0 525 0 0 0 0 0 574 0 0 0 0 0 574 0 0 0 0 0
1354 1001 708 1074 0 0 0 1098 659 1025 0 0 0 1037 720 988 586 488 1013 1281
696 757 1977 488 744 635 647 879 2038 403 635 415 757 793 1903 574 757 427 744 830
and a list of the top 10% highest values
VsortN =
1074
1098
1123
1147
1159
1184
1196
1196
1208
1281
1354
1903
1977
2038
I now want to put all of these values to zero, I have tried:
BIM2=BIM2(BIM2==VsortN)==0 ;
But this doesn't work
0 comentarios
Respuesta aceptada
Geoff Hayes
el 25 de En. de 2016
Editada: Geoff Hayes
el 25 de En. de 2016
Jason - when comparing
BIM2==VsortN
are you observing an error along the lines of
Error using ==
Matrix dimensions must agree.
This error makes sense because the code is trying to compare two matrices of different dimensions. You could try using ismember instead as
BIM2(ismember(BIM2,VsortN)) = 0;
where ismember returns a logical array of ones and zeros indicating whether the element of BIM2 is a member of VsortN or isn't respectively.
There may be more efficient ways to do the above so be wary if using large matrices.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!