【发布时间】:2012-06-09 12:05:04
【问题描述】:
我需要使用 arrayfun 构建一个 ID 类的对象数组:
% ID.m
classdef ID < handle
properties
id
end
methods
function obj = ID(id)
obj.id = id;
end
end
end
但是得到一个错误:
>> ids = 1:5;
>> s = arrayfun(@(id) ID(id), ids)
??? Error using ==> arrayfun
ID output type is not currently implemented.
我可以循环构建它:
s = [];
for k = 1 : length(ids)
s = cat(1, s, ID(ids(k)));
end
但是arrayfun 的这种用法有什么问题呢?
编辑(澄清问题):问题不是如何解决问题(有几种解决方案),而是为什么简单的语法s = arrayfun(@(id) ID(id), ids); 不起作用。谢谢。
【问题讨论】: