Why I recive such an answer:"Incorrect number or types of inputs or outputs for function range."

256 views (last 30 days)
I wrote the following codes:
x = [1 -1.65 2.2 -3.1];
y = range(x)
But MATLAB's answer is "Incorrect number or types of inputs or outputs for function range."
Did I made any mistake?
  3 Comments

Sign in to comment.

Accepted Answer

DGM
DGM on 28 Dec 2023
Moved: DGM on 28 Dec 2023
x = [1 -1.65 2.2 -3.1];
y = range(x)
y = 5.3000
The code you posted should work fine. You probably have something shadowing the intended file.
Check the output of
which range -all
/MATLAB/toolbox/stats/stats/range.m /MATLAB/toolbox/shared/channel/rfprop/@txsite/range.m % txsite method /MATLAB/toolbox/stats/distributed/@distributed/range.m % distributed method
If you see some user-created function file in that list, rename it to something other than range.m. Likewise, if this error is happening in some a script or function with a local function called range(), fix that.
  6 Comments
DGM
DGM on 29 Dec 2023
If you want, here's a replacement for range() (attached)
% test row vector
args = {rand(1,100)};
x1 = range(args{:});
x2 = myrange(args{:});
isequal(x1,x2)
ans = logical
1
% test col vector
args = {rand(100,1)};
x1 = range(args{:});
x2 = myrange(args{:});
isequal(x1,x2)
ans = logical
1
% test with specified dimension
args = {rand(100),2};
x1 = range(args{:});
x2 = myrange(args{:});
isequal(x1,x2)
ans = logical
1
I'm just recalling the behavior off the top of my head, but the original implementation should be similar, if not a bit simpler. There's not much to it.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!