Question
How to get the encoded data from a retrained autoencoder? Here is my example: X = bodyfat_dataset; autoenc = trainAutoencoder(X); extract1= encode(autoenc,X)' %convert to a net work net = network(autoenc); Xpred = net(X); %how do i extract the encoded data. %tried this but it did not help extract2 = net.outputs{1}
Expert Answer
John Williams
PhD Expert
Answered Sep 8, 2026
Here are two options you can use:
Option 1:
1. Run the code to train and retrain an autoencoder:
% Train a first sparse autoencoder with default settings. autoenc = trainAutoencoder(X1); % convert this autoencoder into a network: net = network(autoenc); % retrain autoencoder: net = train(net,X2,X2);
2. Then use 'genFunction' to generate a function for the autoencoder network:
genFunction(net);
This will create a new function on the current folder called 'neural_function' that contains the code for the autoencoder 'net'.
The customer could then edit this function so that it outputs the output of layer 1 (a1) (I have attached an example of how the function will look like after the changes).
3. Finally, the encoded data can be obtained by calling 'neural_function' on the new data:
features = neural_function(X1);
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related train Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →