How to create a training data from excel sheet to matlab?
Show older comments
close all; clear all; clc;
%load data & display data1= xlsread('DSN OFFSET.xlsx','R0'); disp(data1);
%filter data(divide training sets and test sets) X = data1(2,:); Y = data1(3,:);
%train = training data
What do i do next?
Answers (1)
Shashika Munasingha
on 3 Jun 2019
Edited: Shashika Munasingha
on 17 May 2020
There is a solution for this. I encountered similar problem and struggled for a while as there was no proper answer found in MatLab community. This is little bit lengthy and may not be the optimum solution, but hopefully this will solve some of your issues.
In my excel/csv, I have feature vector of length 7 and one output.
Here I used MatLab Deep Network Designer Toolbox (quite new toolbox) to generate the layer architecture and designed a nn setting input layer of dimension [7,1,1]. Design your network as you wish, but pay attention to the size of the inputs and outputs from each layer. They must be tallied with the data vectors in your excel/csv.
Import the NN model to MatLab workspace or you can create NN from scratch using code.
%% your layer architecture variable
net_layers
What I am going to highlight here is arranging our data such that it could be fed into our model.
%% importing data from csv file and separating them into target and input arrays %%
[~,~,data] = xlsread('temperature_feature_vector.csv');
data_mat = cell2mat(data);
target_array = categorical(data_mat(:,8));
input_array = data_mat(:,1:7);
%% reshaping input data such that it matches our model 2D ---> 4D
%% there are 53 input vectors in this example
x = reshape(input_array',[7,1,1,53]);
Now you have shaped your data accordingly. You are ready to train your network !!!
%define options for your network. you can change accordingly
options = trainingOptions('sgdm', ...
'ExecutionEnvironment','auto', ...
'InitialLearnRate',0.000003, ...
'LearnRateSchedule','piecewise', ...
'MaxEpochs',10, ...
'MiniBatchSize',1, ...
'SequenceLength','longest', ...
'Shuffle','never', ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(x,target_array,net_layers,options);
With this method you can easily use deep nn models to train your data
Trick is in reshaping your data and defining of layer architecture accordingly.
10 Comments
NICOLE MIN
on 17 May 2020
i got this error:
Caused by:
Error using
nnet.internal.cnn.MiniBatchDatastoreDispatcher
An error occurred while trying to determine whether
"readData" is a function name.
Shashika Munasingha
on 17 May 2020
What is your MatLab version?
NICOLE MIN
on 17 May 2020
I’m using 2018b and 2019a version on 2 different computer
NICOLE MIN
on 18 May 2020
>> data_mat = cell2mat(data);
>> target_array = categorical(data_mat(:,8));
>> input_array = data_mat(:,1:24);
>> x = reshape(input_array',[24,1,1,2049]);
>> layers = [
imageInputLayer([22 1 1]) % 22X1X1 refers to number of features per sample
convolution2dLayer(3,16,'Padding','same')
reluLayer
fullyConnectedLayer(384) % 384 refers to number of neurons in next FC hidden layer
fullyConnectedLayer(384) % 384 refers to number of neurons in next FC hidden layer
fullyConnectedLayer(2) % 2 refers to number of neurons in next output layer (number of output classes)
softmaxLayer
classificationLayer];
>> options = trainingOptions('sgdm', ...
'ExecutionEnvironment','auto', ...
'InitialLearnRate',0.000003, ...
'LearnRateSchedule','piecewise', ...
'MaxEpochs',10, ...
'MiniBatchSize',1, ...
'SequenceLength','longest', ...
'Shuffle','never', ...
'Verbose',0, ...
'Plots','training-progress');
>> net = trainNetwork(x,target_array,layers,options);
this is a code ive followed and input and output created. is it wong somewhere? and i have this error.
Error using trainNetwork (line 150)
An error occurred while trying to determine whether "readData" is a
function name.
Caused by:
An error occurred while trying to determine whether "readData" is a
function name.
Can't reload
'/Applications/MATLAB_R2018b.app/bin/maci64/libmwsl_graphical_classes.dylib'
NICOLE MIN
on 18 May 2020
my data variable
NICOLE MIN
on 18 May 2020
if i just want a 1D cnn, how should i do it?
Shashika Munasingha
on 18 May 2020
Hi Nicole,
This seems to be some file corruption error or installation error in MATLAB. I found this solution for the first issue you encountered.
For 1-d cnn this answer looks like a go!
NICOLE MIN
on 18 May 2020
>> help readData
readData not found
>> doc readData
just to type thesesfew line able to solve my issue, am i right to say that
NICOLE MIN
on 18 May 2020
i got this issue, is matlab version incompatible?

NICOLE MIN
on 18 May 2020
firstly, ive copy the whole chuck of coding from the dic under read entire dataset, issue arises. secondly, ive tried replacing 'TEMPERATURE' TO 'X' same issue occur too. im not sure what is going on . i appreviacte very much if this issue can find a solution. thanks
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!