Unexpected behavior of anonymous function
古いコメントを表示
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 件のコメント
Sean de Wolski
2013 年 1 月 24 日
@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
採用された回答
その他の回答 (1 件)
Sean de Wolski
2013 年 1 月 24 日
0 投票
That certainly looks like obscure behavior.
カテゴリ
ヘルプ センター および File Exchange で Customize Object Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!