无法分配单元格条目



我正在使用一个在输出层中有 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. 

第一: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 

如果有一个内置函数可以做到这一点,那就太好了,但我不知道它是否存在。我尝试过使用匿名函数,但没有设法使其工作。

最新更新