Unexpected behavior of anonymous function
Ältere Kommentare anzeigen
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 Kommentare
Sean de Wolski
am 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
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 24 Jan. 2013
0 Stimmen
That certainly looks like obscure behavior.
Kategorien
Mehr zu Customize Object Indexing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!