Clear Filters
Clear Filters

Error when training neural network: Unable to use a value of type network as an index

7 views (last 30 days)
Hello I get this error when training this neural network
Unable to use a value of type network as an index.
Error in ANN (line 13)
trained_net = train(net,train,targets)
% Load the data set
data = load('data.mat');
data = struct2array(data)
% Extract the data and labels from the table
train = data(:, 1:end-1);
targets = data(:, end);
layer1 = 10
layer2 = 10
net = patternnet([layer1 layer2]);
trained_net = train(net,train,targets)
op = trained_net(train);
conf = confusion(targets,op);
Any help would be greatly appreciated.

Answers (1)

Amey Waghmare
Amey Waghmare on 6 Jan 2023
Hi,
As per my understanding, you are unable to train the neural network because of the error ‘Unable to use a value of type network as an index.’
This error occurs because the name of the variable ‘train’, created from data, matches with the MATLAB’s function ‘train’. In order to resolve the error, change the name of variable ‘train’ to any other name on line 7 of the code, as follows,
train_X = data(:, 1:end-1);
This will resolve the error.
Also, to train the network using the ‘train’ function, the data should be passed as a input size by batch size form. This can be done by using transpose as follows,
train_1 = data(:, 1:end-1)';
targets = data(:, end)';
For more information, please refer the documentation of 'train', https://in.mathworks.com/help/deeplearning/ref/network.train.html
I hope this resolves the issue.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!