1
votes

I am working on neural network project in Simulink. I have trained the neural network in matlab script file and saved the trained data into a .mat file. Now, I have to use this trained data in simulink user defined function where I can utilize this trained data for prediction. I have tried my many ways to load this data into the function but not able to get success.

I tried to load the mat file by load function and get_param function but these are not supported.

I have imported this trained data into workspace using model explorer and model workspace but still unable to get data from this workspace. I wish, I can use this imported workspace trained data into my user defined matlab function in Simulink. I tried to use from workspace block but I think from workspace loads time series data and arrays or may be I am not sure how to used from workspace to load this neural net.

The code for training data and saving into file

net=feedforwardnet([10,5]); 
%set other parameters
net=train(net,[theta1;theta1D;theta1DD;theta2;theta2D;theta2DD],[tau1;tau2]);
save trainednet.mat net;
%theta and tau are the function variables

after this the variable neural network net is imported in workspace. Now I want to used this net in user defined function given

 pridicted=sim(net,[theta1;theta1D;theta1DD;theta2;theta2D;theta2DD]);

Please ask, if any other information is missing. I guess, I could use from worskspace in some different way by saving the file in some different way. But I could not get it well. Using Matlab R2012a

1

1 Answers

1
votes

I was not able to get data from workspace but Function 'load' is supported for code generation when using coder.extrinsic('load') to bypass code generation. Therefore adding these lines solved the problem

coder.extrinsic('load');
net=load('trainednet.mat');