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

前端 未结 1 767
遇见更好的自我
遇见更好的自我 2021-01-29 11:12
    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 Frien

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 12:03

    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.

    0 讨论(0)
提交回复
热议问题