我正在使用一个在输出层有2个节点的神经网络,因此我得到了一个单元v_cell{1,number_of_layers} =[7 ; 8]
。作为我希望分配给数量v_x和v_y到
v_x = cell(1,4999);v_y = cell(1,4999);
[v_x{1,epochs} v_y{1,epochs}] = deal(v_cell{1,number_of_layers})';,
但是我收到以下错误:
Error using ' Too many output arguments.
答案 0 :(得分:1)
首先:deal
没有返回一个数组,所以转置它是没有意义的。
然后v_cell{1,number_of_layers}
是一个数组,[v_x{1,epochs},v_y{1,epochs}] = deal(v_cell{1,number_of_layers});
将其分发到v_x{1,epochs}
和v_y{1,epochs}
,如帮助中所述:
[Y1,Y2,Y3,...] = deal(X)将单个输入复制到所有 要求的产出。它与Y1 = X,Y2 = X,Y3 = X,......
相同
你想要的是Y1 = X(1),Y2 = X(2),......
您可以尝试使用具有非限制数量的输出参数的自定义函数extract
:
[v_x{1,epochs},v_y{1,epochs}] = extract(v_cell{1,number_of_layers});
extract
中可以定义extract.m
:
function varargout=extract(vect)
if ~strcmp(class(vect),class([0,0]))
error('Input argument is not a constant');
end
if numel(vect)~=nargout
error('Number of element in vect and number of output args are different');
end
varargout=num2cell(vect);
end
如果有内置函数可以做到这一点会很好但我不知道它是否存在。我尝试过使用匿名功能,但没有设法使其正常工作。