range isn't working

17 visualizaciones (últimos 30 días)
Evgeny Hahamovich
Evgeny Hahamovich el 30 de Oct. de 2021
Respondida: Evgeny Hahamovich el 30 de Oct. de 2021
Just got the R2021b version and some of my code isn't working :(
The basic function "range" initialy offered me to calculate some wave propogation parameters, I solved this by removing the Communications Toolbox, but now it's not working at all!
Here is an example of the error:
a=[1 2 3]
>> range(a)
'range' requires one of the following:
Antenna Toolbox
Communications Toolbox
Fixed-Point Designer
Statistics and Machine Learning Toolbox
>> range(a,'all')
'range' requires one of the following:
Antenna Toolbox
Communications Toolbox
Fixed-Point Designer
Statistics and Machine Learning Toolbox
Very frustrating

Respuesta aceptada

Chris
Chris el 30 de Oct. de 2021
Yep, I don't think it's part of base Matlab. It works as you would expect if you install the Statistics and Machine Learning Toolbox.
  1 comentario
Chris
Chris el 30 de Oct. de 2021
Editada: Chris el 30 de Oct. de 2021
You could write your own range function and put it somewhere in your matlab path, if you don't want to install the toolbox. As a simple example, if you only need it to work with vectors:
function y = range(X)
% prevent some invalid inputs
arguments
X (:,1) {mustBeNumeric, mustBeReal}
end
y = max(X)-min(X);
end
(the full function from the toolbox is not much more complicated, but I'm not sure about the legality of posting it here)

Iniciar sesión para comentar.

Más respuestas (3)

DGM
DGM el 30 de Oct. de 2021
Editada: DGM el 30 de Oct. de 2021
If you don't need to use a dimension input:
A = [1 2 3; 4 5 6; 7 8 9];
range = @(x) max(x) - min(x);
range(A)
ans = 1×3
6 6 6
range(A(:))
ans = 8
If you want to use dimension input
range = @(x,dim) max(x,[],dim) - min(x,[],dim);
range(A,2)
ans = 3×1
2 2 2

Image Analyst
Image Analyst el 30 de Oct. de 2021
What about the built-in bounds() function:
v = 4:99;
[minv, maxv] = bounds(v)
minv =
4
maxv =
99

Evgeny Hahamovich
Evgeny Hahamovich el 30 de Oct. de 2021
Thanks guys for your fast responce.
Added the Statistics and Machine Learning Toolbox, and got my range function back :)
While all other solutions are great, I just don't have the patience to start patching up my old code in order to make it work...

Categorías

Más información sobre Analysis, Benchmarking, and Verification en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by