How do I extract and display weight matrices of hidden layers in a trained MATLAB neural network model?
Neeta Dsouza answered .
2026-07-24
In Deep Learning Toolbox, you can extract weight matrices using net.IW (Input Weights) and net.LW (Layer Weights) or net.Layers for SeriesNetwork/DAGNetwork objects:
% For standard Feedforward Neural Network (net):
W1 = net.IW{1,1}; % Weights from input to 1st hidden layer
figure;
imagesc(W1);
colorbar;
title('Hidden Layer 1 Weight Matrix');
xlabel('Inputs'); ylabel('Neurons');
% For Deep Convolutional Networks (net):
convLayer = net.Layers(2);
W_conv = convLayer.Weights; % Size: [H W C Filters]
montage(rescale(W_conv));
title('Visualized Conv Filter Weights');