"intersect" produces variable of class cast
1 view (last 30 days)
Show older comments
Martin Schmid
on 9 Nov 2015
Commented: Martin Schmid
on 10 Nov 2015
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
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.
Accepted Answer
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.
More Answers (1)
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
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?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!