How do I tell Matlab to use the proper "range" function?

I have a script that I wrote a while ago that started misbehaving after I installed the Antenna Toolbox. This script uses the "range" function to find the largest delta between min and max values in the first column:
myrange = range(myarray,1);
I got an error and then checked the help on this function and found that it's coming from a radio propagation function in that toolbox.
which range
C:\Program Files\MATLAB\R2022a\toolbox\shared\channel\rfprop\@txsite\range.m
How do I get Matlab to use the basic "range" function in my script?
Also, as a followup, I ran:
which range -all
and it only shows the function in that rfprop toolbox. So I don't even know where the original "range" function is supposed to be.

14 commentaires

This range.m you show is private. It will not be called. What is the error message you got?
Andy
Andy le 20 Sep 2022
Modifié(e) : Andy le 20 Sep 2022
The error when running this script in R2022a is:
Check for incorrect argument data type or missing argument in call to function 'range'.
So it was definitely getting called.
I don't get an error when running in R2021a and it performs as expected.
What does it means for a function to be "private"? It doesn't seem like it was private, because "range" was being called by a simple script that was not using the Antenna Toolbox. I was just plotting some simple data that I had in a dataset.
Notice the "@txsite" in the folder? It means this range() function is a method for the txsite class. Usualy only a txsite object can run this range() method. txsite is for creating RF transmitter site.
Maybe I should not say it is private. Take function isequal() for example, when you run isequal(1,1) and isequal('a','b'), different isequal() functions are called. You can run "which -all isequal" to see there are many isequal() function.
MATLAB is able to call the correct isequal() function based on the data class of the input arguments. If you have both range() function available, most likely it will find the correct one.
It sounds like there might be a bug, because I never use classes, methods or objects. I was using simple numeric variables defined in the most basic way.
It is too late now, but in future you can track more specifically by using
which range(myarray,1)
MATLAB will analyze the type of myarray and tell you exactly which range function is being invoked.
I would not regard this as a bug. Technically, we should call \stats\range() or txsite.range() based on the use case. MATLAB provides this convenience by adding all functions into the path and being able to call the right function based on the use case. I like this feature. There are so many operations bear the same name, such as open, save, delete a varible, or a file, or an audio, or a video.
The root cause of your problem was that you don't have that function you meant to call. We took the convenience provided by MATLAB for granted.
I was only calling it a bug in reference to the expected behavior that you described, because I definitely wasn't using any objects:
"Notice the "@txsite" in the folder? It means this range() function is a method for the txsite class. Usualy only a txsite object can run this range() method."
When I look in the @txsite code, range() appears to be a hidden method, and is not marked as a static method. So txsite.range() should not ever be invoked unless the parameter was a txsite object (or derived from one.)
It is not possible to add a @ directory to the MATLAB path; addpath() will refuse it. So it is not possible for range() of @txsite to accidentally end up on the path for non-txsite objects. Methods defined in a @directory that are not marked as static can only be invoked by the class.
This is why it would have been useful to which range(myarray,1) while the problem was occuring, to figure out exactly what range was resolving to given those parameters.
Is there a way to test this without uninstalling the Statistics Toolbox? Can I disable that toolbox temporarily? Or could I temporarily rename "C:\Program Files\MATLAB\R2022a\toolbox\stats" to "C:\Program Files\MATLAB\R2022a\toolbox\stats_test" to disable it?
You might be able to use pathtool to remove the stats toolbox from your path. Just do not "save" the resulting path.
Hi. I just tested it. I used pathtool to remove the stats toolbox. So it was back to this:
>> which range
C:\Program Files\MATLAB\R2022a\toolbox\shared\channel\rfprop\@txsite\range.m
So then I did this
>> clear
>> a=[1,2;3,4];
>> which range(a,1)
'range(a,1)' not found
So I'm not getting any information from the "which" command here. And then this was back to the original error:
>> range(a,1)
Check for incorrect argument data type or missing argument in call to function 'range'.
So that where I'm at.
Hmmm, I have no explanation at this time.
I noticed this befroe but didn't bring it up. My take is this:
"which -all range" shows all the range.m files in the path. It also shows the range.m files inside a class, which is surprised to me. For example
\toolbox\stats\stats\range.m
\toolbox\fixedpoint\fixedpoint\@embedded\@numerictype\range.m % embedded.numerictype method
\toolbox\mbc\mbcmodels\@xregexportmodel\range.m % xregexportmodel method
\toolbox\mbc\mbcmodels\@xregmodel\range.m % xregmodel method
\toolbox\mbc\mbctools\@sweepset\range.m % sweepset method
\toolbox\shared\channel\rfprop\@txsite\range.m % txsite method
\toolbox\stats\distributed\@distributed\range.m
"which range(1:4)" tries to find a range.m that fits the input argument. If you remove \toolbox\stats\stats from the path, then it won't find any range.m that fits it. So the " 'range(1:4)' not found" message makes sense.
After removing \toolbox\stats\stats from the path, if you run range(1:4), I got the error message in R2022b
"Incorrect number or types of inputs or outputs for function 'range'"
My guess is that it didn't find the right fit, so it ran the first range.m and gave error message regarding incorrect number or types, because it didn't know whether the user didn't intend to use this range.m, or, the user intended to use this range.m but made mistake providing inputs.
In summary:
"which range(1:4)", it can afford to tell you that there is no matching range.m
"range(1:4)", It can't affort to tell you that range.m does not exist. It tells you that range.m does exist, but there is an error running it.
Of course, all this can be changed. It is up to the Mathworks how to present the message.

Connectez-vous pour commenter.

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 20 Sep 2022
Modifié(e) : Fangjun Jiang le 20 Sep 2022

0 votes

Run "which -all range".
The first one is used. The rests are shadowed, or private which will not affect you.
The 'the basic "range" function' comes from this toolbox. Make sure you have it.
\toolbox\stats\stats\range.m

7 commentaires

Andy
Andy le 20 Sep 2022
Modifié(e) : Andy le 20 Sep 2022
I updated my question just as you posted. I tried
which range -all
which -all range
They both show just the weird one.
I tested my installation of R2021a and it has the proper range function. Maybe the stats toolbox didn't get installed during my R2022a installation.
Then you don't have the stats toolbox and you don't have the range function. Your error is probably "unrecognized function or variable range"
@Andy: do you have the statistics toolbox installed and a valid license for it?
The error is:
Check for incorrect argument data type or missing argument in call to function 'range'.
@Stephen23: Yes, that was the problem. My IT person neglected to install the statistics toolbox. I installed it and now it pulls the proper range function before trying to reach that other range function.
@txsite\range.m can only get called for objects of class txsite, unless range happens to be defined as a static method of class txsite.
I don't know how to use classes or methods. I was just performing some simple plotting of basic 2 dimensional numeric arrays that I had stored from some previous measurements.

Connectez-vous pour commenter.

Produits

Version

R2022a

Question posée :

le 20 Sep 2022

Modifié(e) :

le 30 Sep 2022

Community Treasure Hunt

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

Start Hunting!

Translated by