"intersect" produces variable of class cast

1 view (last 30 days)
In Matlab R2010a, version 7.10.0.499, I enter the following statements:
a = [10 20];
b = [30 10];
c = intersect (a,b);
and expect the result c = 10
But Matlab returns:
c =
object of class 'cast'
data description : -not available-
data : 10.00
data unit : double
var description : -not available-
var : -not available-
var unit : -not available-
dVar : -empty-
sample frequency : -empty-
leftCutOff : 1
rightCutOff : 1
What could be the reason, and how can I resolve this?
  1 Comment
Geoff Hayes
Geoff Hayes on 9 Nov 2015
Martin - perhaps you written a function called intersect that is overwriting the above. In the Command Window, type the following
which -all intersect
to see which intersect functions you have.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 9 Nov 2015
What does this command return?
which -all cast
My guess is that you have an object named cast on your path and it is being used instead of the MATLAB function named CAST.
Given how frequently CAST is used in handling different types of data that are passed into functions (casting one of the inputs into the type of the other or casting both into a common type) I strongly recommend that you rename this class so that it doesn't conflict with the built-in function.
  1 Comment
Martin Schmid
Martin Schmid on 10 Nov 2015
Thanks. This was indeed the culprit. I found a function named cast in a third-party toolbox. Removing this toolbox from the path solved the issue.

Sign in to comment.

More Answers (1)

Adam
Adam on 9 Nov 2015
Edited: Adam on 9 Nov 2015
I suspect you must have your own function called 'intersect' that produces this behaviour
What is the result of typing
which intersect -all
?
It will likely produce quite a significant list, but it will show if you have your own function called intersect on your path that is hiding the builtin version.
When I run your code in R2015b I get exactly what you would expect - i.e. 10 as a 'double'
  2 Comments
Martin Schmid
Martin Schmid on 9 Nov 2015
Thanks for your reply, but I don' think this is the case. Here is the result of "which intersect -all"
C:\Program Files\MATLAB\R2010a\toolbox\matlab\ops\intersect.m
C:\Program Files\MATLAB\R2010a\toolbox\matlab\ops\@cell\intersect.m % cell method
C:\Program Files\MATLAB\R2010a\toolbox\shared\statslib\@ordinal\intersect.m % ordinal method
C:\Program Files\MATLAB\R2010a\toolbox\shared\statslib\@nominal\intersect.m % nominal method
C:\Program Files\MATLAB\R2010a\toolbox\shared\statslib\@categorical\intersect.m % categorical method
Adam
Adam on 9 Nov 2015
Edited: Adam on 9 Nov 2015
Do you get the same answer if you remove everything from your path except the Matlab builtin and toolbox functions?
It is possible that while you haven't overwritten the intersect function you may have overwritten one of the functions that it itself calls.
Also, what is the result of
which cast -all
with your path as it is right now?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!