How to Visualize Hidden Layer Weights in a MATLAB Neural Network?

Illustration
support - 2026-07-24T11:22:44+05:30
Question: How to Visualize Hidden Layer Weights in a MATLAB Neural Network?

How do I extract and display weight matrices of hidden layers in a trained MATLAB neural network model?

Expert Answer

Profile picture of Neeta Dsouza 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');


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!