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

11 ビュー (過去 30 日間)
Andy
Andy 2022 年 9 月 20 日
編集済み: Fangjun Jiang 2022 年 9 月 30 日
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 件のコメント
Fangjun Jiang
Fangjun Jiang 2022 年 9 月 30 日
編集済み: Fangjun Jiang 2022 年 9 月 30 日
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.

サインインしてコメントする。

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2022 年 9 月 20 日
編集済み: Fangjun Jiang 2022 年 9 月 20 日
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 件のコメント
Andy
Andy 2022 年 9 月 20 日
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.

サインインしてコメントする。

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by