Borrar filtros
Borrar filtros

Comparing values in an array to a range

5 visualizaciones (últimos 30 días)
Matlabhelp
Matlabhelp el 28 de Sept. de 2016
Comentada: Rik el 25 de Ag. de 2020
Hello
I'm wondering how to compare my values in an array ( 20x20) to a certain range, if found within that certain range will display the given value for the range. For example the array consists of numbers between ( 1 - 5, inclusive of decimal numbers such as 1.5, 0.5, 3.5 etc ) i have 5 given ranges, one being 0.5 - 1, and if that value is found between those numbers it will display a 1 for that number. And if it was found between 1.1-1.6 it will display a 2. I want to be able to compare each number to each range in one short code but don't know how
  1 comentario
Rik
Rik el 25 de Ag. de 2020
Copy of the question in case he deletes this one as well:
Comparing values in an array to a range
Hello
I'm wondering how to compare my values in an array ( 20x20) to a certain range, if found within that certain range will display the given value for the range. For example the array consists of numbers between ( 1 - 5, inclusive of decimal numbers such as 1.5, 0.5, 3.5 etc ) i have 5 given ranges, one being 0.5 - 1, and if that value is found between those numbers it will display a 1 for that number. And if it was found between 1.1-1.6 it will display a 2. I want to be able to compare each number to each range in one short code but don't know how

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 28 de Sept. de 2016
Editada: Andrei Bobrov el 28 de Sept. de 2016
a = rand(20,20)*5;
edges = [.5,1,1.1,1.6];
ii = discretize(a,edges);% [~,ii] = histc(a,edges) - if MATLAB older then R2014b
w = [1 0 2 ];
ii(ii>0) = w(ii(ii>0));
Please read about discretize and histcounts.
OR
t1 = a >= .5 & a < 1;
t2 = a >=1.1 & a < 1.6;
ii = t1 + 2*t2;

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by