Effacer les filtres
Effacer les filtres

Comparing my array to a certain range

3 vues (au cours des 30 derniers jours)
Matlabhelp
Matlabhelp le 29 Sep 2016
Commenté : Image Analyst le 25 Août 2020
Hello again ( a lot of questions i know )
In my array i want to compare each value in that array to a certain range, for example, if a number in that array is between two certain values, e.g between 1-2, i want that number which falls in between that range to display another value. So if that number was 1.5 it would display a 1 instead, if it were at 1.8 it would display 1 as well. How do i compare my whole array to suit a certain range and then display a given variable for the respective range.
  1 commentaire
Image Analyst
Image Analyst le 25 Août 2020
Original question in case he deletes is like he's done with other posts.
Hello again ( a lot of questions i know )
In my array i want to compare each value in that array to a certain range, for example, if a number in that array is between two certain values, e.g between 1-2, i want that number which falls in between that range to display another value. So if that number was 1.5 it would display a 1 instead, if it were at 1.8 it would display 1 as well. How do i compare my whole array to suit a certain range and then display a given variable for the respective range.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 29 Sep 2016
clc; clear all ;
% generate random data netween 0 and 2
a = 0;
b = 3;
r = (b-a).*rand(20,1) + a;
r(r>1 & r< 2) = 2 ; % replace numbers greater then 1 and less then 2 with 2
read about find
  1 commentaire
Matlabhelp
Matlabhelp le 29 Sep 2016
Thank you, absolute legend !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by