Problem with dismatch dimension in arrayfun

t=0:.1:2*pi;
eln=@(n,col) line("xdata", n*cos(t),	"ydata", n*sin(t), "color", col);
axis("equal");
eln(1,"b");
eln(1.2,[0 1 0]);
arrayfun(eln, 1.4:.2:1.6,["b","g"]);
#arrayfun(eln, 1.8:.2:2.0,[[0 0 1],[0 1 0]]);

I want define color with rgb and uncommenting last string give me error

error: arrayfun: dimensions mismatch

Two arrays cannot be passed this way to arrayfun. Both will be merged to a single array:

>> [[0 0 1],[0 1 0]]
ans =

   0   0   1   0   1   0

Using cellfun instead might be an option:

t=0:.1:2*pi;
eln=@(n,col) line("xdata", n*cos(t),	"ydata", n*sin(t), "color", col);
axis("equal");
eln(1,"b");
eln(1.2,[0 1 0]);
arrayfun(eln, 1.4:.2:1.6,["b","g"]);
cellfun (eln, num2cell (1.8:.2:2.0), {[0 0 1],[0 1 0]});
1 Like