oop - Matlab's arrayfun for uniform output of class objects -


i need build array of objects of class id using arrayfun:

% id.m classdef id < handle     properties         id     end     methods         function obj = id(id)             obj.id = id;         end     end end 

but error:

>> ids = 1:5; >> s = arrayfun(@(id) id(id), ids)  ??? error using ==> arrayfun id output type not implemented. 

i can build alternatively in loop:

s = []; k = 1 : length(ids)     s = cat(1, s, id(ids(k))); end 

but wrong usage of arrayfun?

edit (clarification of question): question not how workaround problem (there several solutions), why simple syntax s = arrayfun(@(id) id(id), ids); doesn't work. thanks.

you asking arrayfun isn't built do.

the output arrayfun must be:

scalar values (numeric, logical, character, or structure) or cell arrays.

objects don't count of scalar types, why "workarounds" involve using cell array output. 1 thing try using cell2mat convert output desired form; can done in 1 line. (i haven't tested though.)

s = cell2mat(arrayfun(@(id) id(id), ids,'uniformoutput',false)); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -