Unexpected behavior of anonymous function
Afficher commentaires plus anciens
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 commentaires
Sean de Wolski
le 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
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 24 Jan 2013
0 votes
That certainly looks like obscure behavior.
Catégories
En savoir plus sur Customize Object Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!