Unexpected behavior of anonymous function
Show older comments
The anonymous function k below behaves correcltly except for the last two cases k(1,1,:) and k(1,2,:), where it interprets the semicolon as a charcter (':'=58, 58^2=3364), while it should return the handle in the first case and error in the second. Any explanations?
>> k=@(varargin) cellfun(@(x) x^2,varargin)
k =
@(varargin)cellfun(@(x)x^2,varargin)
>> k(:)
ans =
@(varargin)cellfun(@(x)x^2,varargin)
>> k(1)
ans =
1
>> k(1,:)
ans =
@(varargin)cellfun(@(x)x^2,varargin)
>> k(1,2)
ans =
1 4
>> k(1,1,:)
ans =
1 1 3364
>> k(1,2,:)
ans =
1 4 3364
3 Comments
Sean de Wolski
on 24 Jan 2013
@Cedric, apparently. I'm just puzzled by the discrepancy between the second and third dimension.
@Sean: yes, it is as if when S.subs is larger than 2, subs are not treated the same way.. and it is not the position of ':' in the subs that matters:
>> k(:,1,2)
ans = 3364 1 4
Accepted Answer
More Answers (1)
Sean de Wolski
on 24 Jan 2013
0 votes
That certainly looks like obscure behavior.
Categories
Find more on Customize Object Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!