In an assignment A(:) = B, the number of elements in A and B must be the same

你说的曾经没有我的故事 提交于 2019-12-02 22:47:04

问题


    if (hidden_layer>1)
        for i =1 :hidden_layer 
       start_hidden_layer(i) = rand([gk(i+1),(gk(i)+1)])-0.5 ; 
        end
    end

hi Friends. I know every iteration was changed start_hidden_layer matrix dimensional.But all start_hidden_layer values must saved. How to solve this problem?

firstly hidden_layer>1

gk(i) is integer value for example 5 , 3, 8


回答1:


Since you're calling rand with different matrix sizes on each iteration, you cannot save the results into a normal matrix. You need to use a cell matrix to store the result, like this:

%//preallocate the cell array
start_hidden_layer = cell(1, hidden_layer);

for i = 1:hidden_layer
    start_hidden_layer{i} = rand([gk(i+1), (gk(i)+1)]) - 0.5; 
end

For more on cell arrays and how to use them, see this Mathworks help doc.



来源:https://stackoverflow.com/questions/29352647/in-an-assignment-a-b-the-number-of-elements-in-a-and-b-must-be-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!