Category: Matlab
Category Archives: Matlab
Performance-wise, should I create my App Interactively using app designer or code it from the startupFcn(app)?
I am creating an application in MATLAB r2020b, which has a lot og UI elements (mainly uibuttons and uitextarea). I have a total of ~1000 elements organized in a gridlayout.
I am creating all the elements programatically in the startupFcn(app), but It takes a long time to open the app (~1 min).
Would it improve the perfomance of my app if I create all the elements interactively using app designer???I am creating an application in MATLAB r2020b, which has a lot og UI elements (mainly uibuttons and uitextarea). I have a total of ~1000 elements organized in a gridlayout.
I am creating all the elements programatically in the startupFcn(app), but It takes a long time to open the app (~1 min).
Would it improve the perfomance of my app if I create all the elements interactively using app designer??? I am creating an application in MATLAB r2020b, which has a lot og UI elements (mainly uibuttons and uitextarea). I have a total of ~1000 elements organized in a gridlayout.
I am creating all the elements programatically in the startupFcn(app), but It takes a long time to open the app (~1 min).
Would it improve the perfomance of my app if I create all the elements interactively using app designer??? matlab, app designer MATLAB Answers — New Questions
Timer function to refresh the data
Hello,
I want to make an application that allows me to load the file, process the data and display on a graph. I would like to refresh the data every 5 seconds, by restarting the "live" function, but I have trouble understanding the "Timer" function.
Do you have any ideas?Thank you in advance.
function LiveButtonPushed(app, event)
%utilisation de la fonction charger
donnees=charger(app.entrees,app.variables_stockees.conditions_essai.plan);
app.variables_stockees.entrees=app.entrees;
app.variables_stockees.donnees=donnees;
%utilisation de la fonction masquer
masque=masquer(app.variables_stockees);
app.variables_stockees.masque=masque;
%calcul
calcul(app.variables_stockees,app);
timerObj = timer(‘TimerFcn’, @app.LiveButtonPushed, ‘Period’, 5);
start (timerObj);
endHello,
I want to make an application that allows me to load the file, process the data and display on a graph. I would like to refresh the data every 5 seconds, by restarting the "live" function, but I have trouble understanding the "Timer" function.
Do you have any ideas?Thank you in advance.
function LiveButtonPushed(app, event)
%utilisation de la fonction charger
donnees=charger(app.entrees,app.variables_stockees.conditions_essai.plan);
app.variables_stockees.entrees=app.entrees;
app.variables_stockees.donnees=donnees;
%utilisation de la fonction masquer
masque=masquer(app.variables_stockees);
app.variables_stockees.masque=masque;
%calcul
calcul(app.variables_stockees,app);
timerObj = timer(‘TimerFcn’, @app.LiveButtonPushed, ‘Period’, 5);
start (timerObj);
end Hello,
I want to make an application that allows me to load the file, process the data and display on a graph. I would like to refresh the data every 5 seconds, by restarting the "live" function, but I have trouble understanding the "Timer" function.
Do you have any ideas?Thank you in advance.
function LiveButtonPushed(app, event)
%utilisation de la fonction charger
donnees=charger(app.entrees,app.variables_stockees.conditions_essai.plan);
app.variables_stockees.entrees=app.entrees;
app.variables_stockees.donnees=donnees;
%utilisation de la fonction masquer
masque=masquer(app.variables_stockees);
app.variables_stockees.masque=masque;
%calcul
calcul(app.variables_stockees,app);
timerObj = timer(‘TimerFcn’, @app.LiveButtonPushed, ‘Period’, 5);
start (timerObj);
end timer MATLAB Answers — New Questions
Fsolve iter display not printing
I am trying to use Fsolve with the display option, but I don’t see anything being displayed while the function is running. What could be wrong? Here’s an excerpt of my code.
options = optimoptions(‘fsolve’,’Display’,’iter-detailed’);
disp("Starting fsolve")
cf = @calF;
u = fsolve(cf,ucp,options);I am trying to use Fsolve with the display option, but I don’t see anything being displayed while the function is running. What could be wrong? Here’s an excerpt of my code.
options = optimoptions(‘fsolve’,’Display’,’iter-detailed’);
disp("Starting fsolve")
cf = @calF;
u = fsolve(cf,ucp,options); I am trying to use Fsolve with the display option, but I don’t see anything being displayed while the function is running. What could be wrong? Here’s an excerpt of my code.
options = optimoptions(‘fsolve’,’Display’,’iter-detailed’);
disp("Starting fsolve")
cf = @calF;
u = fsolve(cf,ucp,options); fsolve MATLAB Answers — New Questions
Dot indexing is not supported for variables of this type
Hello Everyone,
I am trying to implement a new stand alone function to load a mat file (which has 3 timeseries in it) : (for example: Data.Signal1.Data,) and plot it.
The App is functional within Matlab app designer, but when i build a stand alone application, this error occured:
Dot indexing is not supported for variables of this type.
Unfortunatly i can not find the solution for that. could you please help me about it?
properties (Access = public)
DataMeas = struct; % Description
end
% Button pushed function: OpenCalcmFile
function OpenCalcmFileButtonPushed(app, event)
[file,path] = uigetfile();
if isequal(file,0)
app.CalcmFilePath.Value = "";
else
app.CalcmFilePath.Value = append(path,file);
app.DataMeas = load(append(path,file));
end
function OpenMatFileButtonPushed(app, event)
plot(app.Plot_graph1,app.DataMeas.signal1.Data);
end
Error in log:
Dot indexing is not supported for variables of this type.
Error in TestAutomation/OpenMatFileButtonPushed (line 766)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 368)
Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Error while evaluating Button PrivateButtonPushedFcn.Hello Everyone,
I am trying to implement a new stand alone function to load a mat file (which has 3 timeseries in it) : (for example: Data.Signal1.Data,) and plot it.
The App is functional within Matlab app designer, but when i build a stand alone application, this error occured:
Dot indexing is not supported for variables of this type.
Unfortunatly i can not find the solution for that. could you please help me about it?
properties (Access = public)
DataMeas = struct; % Description
end
% Button pushed function: OpenCalcmFile
function OpenCalcmFileButtonPushed(app, event)
[file,path] = uigetfile();
if isequal(file,0)
app.CalcmFilePath.Value = "";
else
app.CalcmFilePath.Value = append(path,file);
app.DataMeas = load(append(path,file));
end
function OpenMatFileButtonPushed(app, event)
plot(app.Plot_graph1,app.DataMeas.signal1.Data);
end
Error in log:
Dot indexing is not supported for variables of this type.
Error in TestAutomation/OpenMatFileButtonPushed (line 766)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 368)
Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Error while evaluating Button PrivateButtonPushedFcn. Hello Everyone,
I am trying to implement a new stand alone function to load a mat file (which has 3 timeseries in it) : (for example: Data.Signal1.Data,) and plot it.
The App is functional within Matlab app designer, but when i build a stand alone application, this error occured:
Dot indexing is not supported for variables of this type.
Unfortunatly i can not find the solution for that. could you please help me about it?
properties (Access = public)
DataMeas = struct; % Description
end
% Button pushed function: OpenCalcmFile
function OpenCalcmFileButtonPushed(app, event)
[file,path] = uigetfile();
if isequal(file,0)
app.CalcmFilePath.Value = "";
else
app.CalcmFilePath.Value = append(path,file);
app.DataMeas = load(append(path,file));
end
function OpenMatFileButtonPushed(app, event)
plot(app.Plot_graph1,app.DataMeas.signal1.Data);
end
Error in log:
Dot indexing is not supported for variables of this type.
Error in TestAutomation/OpenMatFileButtonPushed (line 766)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 368)
Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Error while evaluating Button PrivateButtonPushedFcn. appdesigner, standaloneapp MATLAB Answers — New Questions
scope displays incorrect waveforms
Using the Repeating Sequence Stair module, when monitoring the waveforms, we found that the output waveforms were not strictly step signals, but had a slight slope as they changed.Using the Repeating Sequence Stair module, when monitoring the waveforms, we found that the output waveforms were not strictly step signals, but had a slight slope as they changed. Using the Repeating Sequence Stair module, when monitoring the waveforms, we found that the output waveforms were not strictly step signals, but had a slight slope as they changed. scope, repeating sequence stair MATLAB Answers — New Questions
Export of simevent-built models
If I can’t export the model built by simevents as code, how do I apply the model to my other codesIf I can’t export the model built by simevents as code, how do I apply the model to my other codes If I can’t export the model built by simevents as code, how do I apply the model to my other codes simevents, export MATLAB Answers — New Questions
Export Simscape Multibody Solid Information
Hi, good day!
Is there a way that I can export the derived values (mass, MOI, Product of Inertia) of all the Solid in a Simscape Multibody model in Excel or any other format?
ThanksHi, good day!
Is there a way that I can export the derived values (mass, MOI, Product of Inertia) of all the Solid in a Simscape Multibody model in Excel or any other format?
Thanks Hi, good day!
Is there a way that I can export the derived values (mass, MOI, Product of Inertia) of all the Solid in a Simscape Multibody model in Excel or any other format?
Thanks simscape, matlab, export MATLAB Answers — New Questions
appdesigner使用setVariable时无法输入参数
在运行时后matlab命令行出现
警告: 正在将调节后的变量 ‘a’ 的工作区从 ‘global-workspace’ 切换到 ‘DXBKQZLDl’ (模型 ‘DXBKQZLDl’ 使用工作区 ‘DXBKQZLDl’ 中的变量)。
> 位置:rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: sl_feval
位置: Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 工作区 ‘DXBKQZLDl’ 中的变量 ‘a’ 会影响不可调节参数的值,因此无法调节。其调节后的值将被忽略。
或
警告: In rapid accelerator mode, when the simulation is started from the command line, visualization blocks are not updated. If the simulation is started
from the toolstrip, visualization blocks are updated.
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘R’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘L’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
>> 请问该怎么解决,谢谢在运行时后matlab命令行出现
警告: 正在将调节后的变量 ‘a’ 的工作区从 ‘global-workspace’ 切换到 ‘DXBKQZLDl’ (模型 ‘DXBKQZLDl’ 使用工作区 ‘DXBKQZLDl’ 中的变量)。
> 位置:rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: sl_feval
位置: Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 工作区 ‘DXBKQZLDl’ 中的变量 ‘a’ 会影响不可调节参数的值,因此无法调节。其调节后的值将被忽略。
或
警告: In rapid accelerator mode, when the simulation is started from the command line, visualization blocks are not updated. If the simulation is started
from the toolstrip, visualization blocks are updated.
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘R’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘L’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
>> 请问该怎么解决,谢谢 在运行时后matlab命令行出现
警告: 正在将调节后的变量 ‘a’ 的工作区从 ‘global-workspace’ 切换到 ‘DXBKQZLDl’ (模型 ‘DXBKQZLDl’ 使用工作区 ‘DXBKQZLDl’ 中的变量)。
> 位置:rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: rapid_accel_target_utils
位置: sl_feval
位置: Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 工作区 ‘DXBKQZLDl’ 中的变量 ‘a’ 会影响不可调节参数的值,因此无法调节。其调节后的值将被忽略。
或
警告: In rapid accelerator mode, when the simulation is started from the command line, visualization blocks are not updated. If the simulation is started
from the toolstrip, visualization blocks are updated.
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘R’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
警告: 变量 ‘L’ (在工作区 ‘global-workspace’ 中)已调节,但未使用其调节后的值。
> 位置:Simulink.Simulation.internal.DesktopSimHelper
位置: Simulink.Simulation.internal.DesktopSimHelper.sim
位置: Simulink/SimulationInput/sim
位置: ZLDL/RunButtonPushed (第 157 行)
位置: matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (第 62 行)
>> 请问该怎么解决,谢谢 app designer, setbvariable MATLAB Answers — New Questions
Export bus datatype from referenced subsystem
I have created a nested bus in a referenced subsystem in simulink and would like to use the bus datatype again in a different model. For this i would like to export the datatype from simulink to a dataDictionary. I tried to open the referenced subsystem in a model and use the commands Simulink.Bus.createObject and Simulink.Bus.save. But i was not able to generate the object in matlab to save it afterwards. Is there a easier solution to this?I have created a nested bus in a referenced subsystem in simulink and would like to use the bus datatype again in a different model. For this i would like to export the datatype from simulink to a dataDictionary. I tried to open the referenced subsystem in a model and use the commands Simulink.Bus.createObject and Simulink.Bus.save. But i was not able to generate the object in matlab to save it afterwards. Is there a easier solution to this? I have created a nested bus in a referenced subsystem in simulink and would like to use the bus datatype again in a different model. For this i would like to export the datatype from simulink to a dataDictionary. I tried to open the referenced subsystem in a model and use the commands Simulink.Bus.createObject and Simulink.Bus.save. But i was not able to generate the object in matlab to save it afterwards. Is there a easier solution to this? simulink, bus, nested bus, bus datatype MATLAB Answers — New Questions
Cannot generate method documentation for abstract class
I’ve the following abstract class:
classdef (Abstract) SessionManager < handle
% SESSIONMANAGER Interface for a generic session manager.
% The session manager has the responsibility to manage the sessions that
% are opened for the system. It also allows to perform some operation on
% them.
methods
b = isSessionOpened(this)
% ISSESSIONOPENED Tells if a session is currently opened in the system.
session = getCurrentSession(this)
% The comment for getting current session
loadSession(this, session)
% another comment
clearSession(this)
% You know what’s this
end
end
When I try to retrieve the help of the class, I can see the description from the command line:
help SessionManager
But when I click on the link for seeing the documentation page. I cannot see the documentation for methods, they are blank:
This is what I see when I click on a link of a custom method:
What I’m doing wrong? How can I document properly the methods?I’ve the following abstract class:
classdef (Abstract) SessionManager < handle
% SESSIONMANAGER Interface for a generic session manager.
% The session manager has the responsibility to manage the sessions that
% are opened for the system. It also allows to perform some operation on
% them.
methods
b = isSessionOpened(this)
% ISSESSIONOPENED Tells if a session is currently opened in the system.
session = getCurrentSession(this)
% The comment for getting current session
loadSession(this, session)
% another comment
clearSession(this)
% You know what’s this
end
end
When I try to retrieve the help of the class, I can see the description from the command line:
help SessionManager
But when I click on the link for seeing the documentation page. I cannot see the documentation for methods, they are blank:
This is what I see when I click on a link of a custom method:
What I’m doing wrong? How can I document properly the methods? I’ve the following abstract class:
classdef (Abstract) SessionManager < handle
% SESSIONMANAGER Interface for a generic session manager.
% The session manager has the responsibility to manage the sessions that
% are opened for the system. It also allows to perform some operation on
% them.
methods
b = isSessionOpened(this)
% ISSESSIONOPENED Tells if a session is currently opened in the system.
session = getCurrentSession(this)
% The comment for getting current session
loadSession(this, session)
% another comment
clearSession(this)
% You know what’s this
end
end
When I try to retrieve the help of the class, I can see the description from the command line:
help SessionManager
But when I click on the link for seeing the documentation page. I cannot see the documentation for methods, they are blank:
This is what I see when I click on a link of a custom method:
What I’m doing wrong? How can I document properly the methods? class, comments, documentation, help comment in wrong place MATLAB Answers — New Questions
Why does the “Matrix dimensions must agree” error persists?
Good evening, I’m trying to plot an audiorecording with an Fs = 8KHz in appdesigner. I created a dropdown but idk why this error remains. I uploaded some images so u can understand me. I’d really apreciate it, its really important to figure it out. Thanks a lot.Good evening, I’m trying to plot an audiorecording with an Fs = 8KHz in appdesigner. I created a dropdown but idk why this error remains. I uploaded some images so u can understand me. I’d really apreciate it, its really important to figure it out. Thanks a lot. Good evening, I’m trying to plot an audiorecording with an Fs = 8KHz in appdesigner. I created a dropdown but idk why this error remains. I uploaded some images so u can understand me. I’d really apreciate it, its really important to figure it out. Thanks a lot. appdesigner, app designer, matlab, matrix, error MATLAB Answers — New Questions
is it possible to recover Livescript after the crash?
I was working on a calculation on Livescript.
Livescript crashed and matlab closed
I re-opened Matlab but Livescript is gone.
Is it possible to recove the Livescript?I was working on a calculation on Livescript.
Livescript crashed and matlab closed
I re-opened Matlab but Livescript is gone.
Is it possible to recove the Livescript? I was working on a calculation on Livescript.
Livescript crashed and matlab closed
I re-opened Matlab but Livescript is gone.
Is it possible to recove the Livescript? matlab, livescript MATLAB Answers — New Questions
How do I connect to a Phasor Measurement Unit (SEL-311C) using it’s serial port RS232? I am able to do that using Teraterm but not in Matlab
I am very new to Matlab. I used Teraterm to communicate with the device (Transmission and protection system SEL-311C). I can send commands and receive the responses in Teraterm but while I try to use Matlab, I cannot get anything. This device is very specific used case device that I am using for my University Project and doesn’t have a big screen where I can verify the data transmission. I am stuck as I want to use a Matlab program to receive the phasor data using this device and analyse the data using a Matlab program.I am very new to Matlab. I used Teraterm to communicate with the device (Transmission and protection system SEL-311C). I can send commands and receive the responses in Teraterm but while I try to use Matlab, I cannot get anything. This device is very specific used case device that I am using for my University Project and doesn’t have a big screen where I can verify the data transmission. I am stuck as I want to use a Matlab program to receive the phasor data using this device and analyse the data using a Matlab program. I am very new to Matlab. I used Teraterm to communicate with the device (Transmission and protection system SEL-311C). I can send commands and receive the responses in Teraterm but while I try to use Matlab, I cannot get anything. This device is very specific used case device that I am using for my University Project and doesn’t have a big screen where I can verify the data transmission. I am stuck as I want to use a Matlab program to receive the phasor data using this device and analyse the data using a Matlab program. serial communication, phasor measurement unit MATLAB Answers — New Questions
How do I disallow students from copying certain parts of the problem on MATLAB Grader?
How do I disallow students from copying certain parts or the entire problem, so that they can’t easily paste it into and generate code using AI tools? Can MATLAB grader render the question as an image? However, students should still be able to copy the variable names, allowing them to satisfy the requirements of the question.How do I disallow students from copying certain parts or the entire problem, so that they can’t easily paste it into and generate code using AI tools? Can MATLAB grader render the question as an image? However, students should still be able to copy the variable names, allowing them to satisfy the requirements of the question. How do I disallow students from copying certain parts or the entire problem, so that they can’t easily paste it into and generate code using AI tools? Can MATLAB grader render the question as an image? However, students should still be able to copy the variable names, allowing them to satisfy the requirements of the question. plagiarism, matlab, grader, chatgpt MATLAB Answers — New Questions
Neural network fitting result problems
Hi, Does any one can teach me how can read the neural network fitting result ? Why my MSE and R is NaN ? And this is good ?
thanks.Hi, Does any one can teach me how can read the neural network fitting result ? Why my MSE and R is NaN ? And this is good ?
thanks. Hi, Does any one can teach me how can read the neural network fitting result ? Why my MSE and R is NaN ? And this is good ?
thanks. machine learning, neural network MATLAB Answers — New Questions
How to use custom DAC using simulink blocksetes for the DSP_28335_DB board have 8 channels 12 bit SPI Protocol
I am using custom DSP_28335 devlopment board, which have 8 channels 12 bit SPI Protocol DAC and Maximum settling time is 6µs. Interface and DAC connector details given below
DAC Address & Channel Selection: DAC Address: 0x10000A
Is there any option to use this DAC using MATLAB/Simulink/C2000 blocksets avaliable in the library.
For example i need to see a Sin wave on the DAC, pleaseI am using custom DSP_28335 devlopment board, which have 8 channels 12 bit SPI Protocol DAC and Maximum settling time is 6µs. Interface and DAC connector details given below
DAC Address & Channel Selection: DAC Address: 0x10000A
Is there any option to use this DAC using MATLAB/Simulink/C2000 blocksets avaliable in the library.
For example i need to see a Sin wave on the DAC, please I am using custom DSP_28335 devlopment board, which have 8 channels 12 bit SPI Protocol DAC and Maximum settling time is 6µs. Interface and DAC connector details given below
DAC Address & Channel Selection: DAC Address: 0x10000A
Is there any option to use this DAC using MATLAB/Simulink/C2000 blocksets avaliable in the library.
For example i need to see a Sin wave on the DAC, please simulink, c2000 MATLAB Answers — New Questions
i have an error at line 13 xi1 and below it. how to correct it for runge kutta method
function [y1] = RK21(x0, y0, h, f)
%RK21.m apply one step of the explicit RK2 method
% with Butcher Tableau:
% 0
% 2/3 2/3
% 1/4 3/4
%
% xi1 = yk
% xi2 = yk + a21*h*f(xk + c1*h, xi1)
% yk+1 = yk + h( b1*f(xk+c1*h, xi1 ) + b2*f(xk+c2*h, xi2)
xi1 = 0;
xi2 = y0 + 2/3*h*f(x1/4+1/4*h, xi3/4);
y1 = y0 + h*( 1/4*f(x1/4+1/4*h, xi3/4) + 3/4*f(x1/4+2/3*h, xi2 ));function [y1] = RK21(x0, y0, h, f)
%RK21.m apply one step of the explicit RK2 method
% with Butcher Tableau:
% 0
% 2/3 2/3
% 1/4 3/4
%
% xi1 = yk
% xi2 = yk + a21*h*f(xk + c1*h, xi1)
% yk+1 = yk + h( b1*f(xk+c1*h, xi1 ) + b2*f(xk+c2*h, xi2)
xi1 = 0;
xi2 = y0 + 2/3*h*f(x1/4+1/4*h, xi3/4);
y1 = y0 + h*( 1/4*f(x1/4+1/4*h, xi3/4) + 3/4*f(x1/4+2/3*h, xi2 )); function [y1] = RK21(x0, y0, h, f)
%RK21.m apply one step of the explicit RK2 method
% with Butcher Tableau:
% 0
% 2/3 2/3
% 1/4 3/4
%
% xi1 = yk
% xi2 = yk + a21*h*f(xk + c1*h, xi1)
% yk+1 = yk + h( b1*f(xk+c1*h, xi1 ) + b2*f(xk+c2*h, xi2)
xi1 = 0;
xi2 = y0 + 2/3*h*f(x1/4+1/4*h, xi3/4);
y1 = y0 + h*( 1/4*f(x1/4+1/4*h, xi3/4) + 3/4*f(x1/4+2/3*h, xi2 )); matlab MATLAB Answers — New Questions
keyboard short cut key for my customized script
I have created a script to get signal name from bus creator. I want to create keyboard short cut key. like after clicking on bus creator ( I have used get(gcbh) to get signals , the list of signal should open.
how to create short cut key to run this scriptI have created a script to get signal name from bus creator. I want to create keyboard short cut key. like after clicking on bus creator ( I have used get(gcbh) to get signals , the list of signal should open.
how to create short cut key to run this script I have created a script to get signal name from bus creator. I want to create keyboard short cut key. like after clicking on bus creator ( I have used get(gcbh) to get signals , the list of signal should open.
how to create short cut key to run this script keyboard short cut keys for script MATLAB Answers — New Questions
Custom training loop, how to do regression for Dlarray type data, I want to do image to image regression,
The code for the model gradient solution I defined is as follows:
function [gradients1,gradients2,gradients3,state1,state2,state3,loss] = modelGradients(dlnet1,dlnet2,dlnet3,dlX1,dlX2,dlY)
[T1,T2,T3,state1] =forward(dlnet1,dlX1);
[t1,t2,t3,state2] =forward(dlnet2,dlX2);
Tt1=T1+t1;
Tt2=T2+t2;
Tt3=T3+t3;
dlX3=cat(3,Tt1,Tt2,Tt3);
[T4,state3] = forward(dlnet3,dlX3);
t4=forward(dlnet1,dlX1,’Outputs’,’resize-output-size’);
Tt4=T4+t4;
loss = mse(Tt4,dlY);%L1loss
[gradients1,gradients2,gradients3]=dlgradient(loss,dlnet1.Learnables,dlnet2.Learnables,dlnet3.Learnables);
end
How to do regression mapping for Dlarray data。
I want to add a regression before “loss = mse(Tt4,dlY);%L1loss”The code for the model gradient solution I defined is as follows:
function [gradients1,gradients2,gradients3,state1,state2,state3,loss] = modelGradients(dlnet1,dlnet2,dlnet3,dlX1,dlX2,dlY)
[T1,T2,T3,state1] =forward(dlnet1,dlX1);
[t1,t2,t3,state2] =forward(dlnet2,dlX2);
Tt1=T1+t1;
Tt2=T2+t2;
Tt3=T3+t3;
dlX3=cat(3,Tt1,Tt2,Tt3);
[T4,state3] = forward(dlnet3,dlX3);
t4=forward(dlnet1,dlX1,’Outputs’,’resize-output-size’);
Tt4=T4+t4;
loss = mse(Tt4,dlY);%L1loss
[gradients1,gradients2,gradients3]=dlgradient(loss,dlnet1.Learnables,dlnet2.Learnables,dlnet3.Learnables);
end
How to do regression mapping for Dlarray data。
I want to add a regression before “loss = mse(Tt4,dlY);%L1loss” The code for the model gradient solution I defined is as follows:
function [gradients1,gradients2,gradients3,state1,state2,state3,loss] = modelGradients(dlnet1,dlnet2,dlnet3,dlX1,dlX2,dlY)
[T1,T2,T3,state1] =forward(dlnet1,dlX1);
[t1,t2,t3,state2] =forward(dlnet2,dlX2);
Tt1=T1+t1;
Tt2=T2+t2;
Tt3=T3+t3;
dlX3=cat(3,Tt1,Tt2,Tt3);
[T4,state3] = forward(dlnet3,dlX3);
t4=forward(dlnet1,dlX1,’Outputs’,’resize-output-size’);
Tt4=T4+t4;
loss = mse(Tt4,dlY);%L1loss
[gradients1,gradients2,gradients3]=dlgradient(loss,dlnet1.Learnables,dlnet2.Learnables,dlnet3.Learnables);
end
How to do regression mapping for Dlarray data。
I want to add a regression before “loss = mse(Tt4,dlY);%L1loss” how to find regression for dlarray type data MATLAB Answers — New Questions
how can I connect more than two inputs to my narx model? why is the scope showing only a dot?
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 11-Apr-2024 12:53:07
%
% This script assumes these variables are defined:
%
% input – input time series.
% output – feedback time series.
X = tonndata(input,false,false);
T = tonndata(output,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:4;
feedbackDelays = 1:4;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’,trainFcn);
% Choose Input and Feedback Pre/Post-Processing Functions
% Settings for feedback input are automatically applied to feedback output
% For a list of all processing functions type: help nnprocess
% Customize input parameters at: net.inputs{i}.processParam
% Customize output parameters at: net.outputs{i}.processParam
net.inputs{1}.processFcns = {‘removeconstantrows’,’mapminmax’};
net.inputs{2}.processFcns = {‘removeconstantrows’,’mapminmax’};
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = ‘dividerand’; % Divide data randomly
net.divideMode = ‘time’; % Divide up every sample
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 5/100;
net.divideParam.testRatio = 15/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = ‘mse’; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {‘plotperform’,’plottrainstate’, ‘ploterrhist’, …
‘plotregression’, ‘plotresponse’, ‘ploterrcorr’, ‘plotinerrcorr’};
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = gmultiply(t,tr.trainMask);
valTargets = gmultiply(t,tr.valMask);
testTargets = gmultiply(t,tr.testMask);
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotresponse(t,y)
%figure, ploterrcorr(e)
%figure, plotinerrcorr(x,e)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the output layer.
netc = closeloop(net);
netc.name = [net.name ‘ – Closed Loop’];
view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc)
% Multi-step Prediction
% Sometimes it is useful to simulate a network in open-loop form for as
% long as there is known output data, and then switch to closed-loop form
% to perform multistep prediction while providing only the external input.
% Here all but 5 timesteps of the input series and target series are used
% to simulate the network in open-loop form, taking advantage of the higher
% accuracy that providing the target series produces:
numTimesteps = size(x,2);
knownOutputTimesteps = 1:(numTimesteps-5);
predictOutputTimesteps = (numTimesteps-4):numTimesteps;
X1 = X(:,knownOutputTimesteps);
T1 = T(:,knownOutputTimesteps);
[x1,xio,aio] = preparets(net,X1,{},T1);
[y1,xfo,afo] = net(x1,xio,aio);
% Next the the network and its final states will be converted to
% closed-loop form to make five predictions with only the five inputs
% provided.
x2 = X(1,predictOutputTimesteps);
[netc,xic,aic] = closeloop(net,xfo,afo);
[y2,xfc,afc] = netc(x2,xic,aic);
multiStepPerformance = perform(net,T(1,predictOutputTimesteps),y2)
% Alternate predictions can be made for different values of x2, or further
% predictions can be made by continuing simulation with additional external
% inputs and the last closed-loop states xfc and afc.
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
nets = removedelay(net);
nets.name = [net.name ‘ – Predict One Step Ahead’];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
genFunction(net,’myNeuralNetworkFunction’);
y = myNeuralNetworkFunction(x,xi,ai);
end
if (false)
% Generate a matrix-only MATLAB function for neural network code
% generation with MATLAB Coder tools.
genFunction(net,’myNeuralNetworkFunction’,’MatrixOnly’,’yes’);
x1 = cell2mat(x(1,:));
x2 = cell2mat(x(2,:));
xi1 = cell2mat(xi(1,:));
xi2 = cell2mat(xi(2,:));
y = myNeuralNetworkFunction(x1,x2,xi1,xi2);
end
if (false)
% Generate a Simulink diagram for simulation or deployment with.
% Simulink Coder tools.
gensim(net);
end% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 11-Apr-2024 12:53:07
%
% This script assumes these variables are defined:
%
% input – input time series.
% output – feedback time series.
X = tonndata(input,false,false);
T = tonndata(output,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:4;
feedbackDelays = 1:4;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’,trainFcn);
% Choose Input and Feedback Pre/Post-Processing Functions
% Settings for feedback input are automatically applied to feedback output
% For a list of all processing functions type: help nnprocess
% Customize input parameters at: net.inputs{i}.processParam
% Customize output parameters at: net.outputs{i}.processParam
net.inputs{1}.processFcns = {‘removeconstantrows’,’mapminmax’};
net.inputs{2}.processFcns = {‘removeconstantrows’,’mapminmax’};
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = ‘dividerand’; % Divide data randomly
net.divideMode = ‘time’; % Divide up every sample
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 5/100;
net.divideParam.testRatio = 15/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = ‘mse’; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {‘plotperform’,’plottrainstate’, ‘ploterrhist’, …
‘plotregression’, ‘plotresponse’, ‘ploterrcorr’, ‘plotinerrcorr’};
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = gmultiply(t,tr.trainMask);
valTargets = gmultiply(t,tr.valMask);
testTargets = gmultiply(t,tr.testMask);
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotresponse(t,y)
%figure, ploterrcorr(e)
%figure, plotinerrcorr(x,e)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the output layer.
netc = closeloop(net);
netc.name = [net.name ‘ – Closed Loop’];
view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc)
% Multi-step Prediction
% Sometimes it is useful to simulate a network in open-loop form for as
% long as there is known output data, and then switch to closed-loop form
% to perform multistep prediction while providing only the external input.
% Here all but 5 timesteps of the input series and target series are used
% to simulate the network in open-loop form, taking advantage of the higher
% accuracy that providing the target series produces:
numTimesteps = size(x,2);
knownOutputTimesteps = 1:(numTimesteps-5);
predictOutputTimesteps = (numTimesteps-4):numTimesteps;
X1 = X(:,knownOutputTimesteps);
T1 = T(:,knownOutputTimesteps);
[x1,xio,aio] = preparets(net,X1,{},T1);
[y1,xfo,afo] = net(x1,xio,aio);
% Next the the network and its final states will be converted to
% closed-loop form to make five predictions with only the five inputs
% provided.
x2 = X(1,predictOutputTimesteps);
[netc,xic,aic] = closeloop(net,xfo,afo);
[y2,xfc,afc] = netc(x2,xic,aic);
multiStepPerformance = perform(net,T(1,predictOutputTimesteps),y2)
% Alternate predictions can be made for different values of x2, or further
% predictions can be made by continuing simulation with additional external
% inputs and the last closed-loop states xfc and afc.
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
nets = removedelay(net);
nets.name = [net.name ‘ – Predict One Step Ahead’];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
genFunction(net,’myNeuralNetworkFunction’);
y = myNeuralNetworkFunction(x,xi,ai);
end
if (false)
% Generate a matrix-only MATLAB function for neural network code
% generation with MATLAB Coder tools.
genFunction(net,’myNeuralNetworkFunction’,’MatrixOnly’,’yes’);
x1 = cell2mat(x(1,:));
x2 = cell2mat(x(2,:));
xi1 = cell2mat(xi(1,:));
xi2 = cell2mat(xi(2,:));
y = myNeuralNetworkFunction(x1,x2,xi1,xi2);
end
if (false)
% Generate a Simulink diagram for simulation or deployment with.
% Simulink Coder tools.
gensim(net);
end % Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 11-Apr-2024 12:53:07
%
% This script assumes these variables are defined:
%
% input – input time series.
% output – feedback time series.
X = tonndata(input,false,false);
T = tonndata(output,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:4;
feedbackDelays = 1:4;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,’open’,trainFcn);
% Choose Input and Feedback Pre/Post-Processing Functions
% Settings for feedback input are automatically applied to feedback output
% For a list of all processing functions type: help nnprocess
% Customize input parameters at: net.inputs{i}.processParam
% Customize output parameters at: net.outputs{i}.processParam
net.inputs{1}.processFcns = {‘removeconstantrows’,’mapminmax’};
net.inputs{2}.processFcns = {‘removeconstantrows’,’mapminmax’};
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = ‘dividerand’; % Divide data randomly
net.divideMode = ‘time’; % Divide up every sample
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 5/100;
net.divideParam.testRatio = 15/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = ‘mse’; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {‘plotperform’,’plottrainstate’, ‘ploterrhist’, …
‘plotregression’, ‘plotresponse’, ‘ploterrcorr’, ‘plotinerrcorr’};
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = gmultiply(t,tr.trainMask);
valTargets = gmultiply(t,tr.valMask);
testTargets = gmultiply(t,tr.testMask);
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotresponse(t,y)
%figure, ploterrcorr(e)
%figure, plotinerrcorr(x,e)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the output layer.
netc = closeloop(net);
netc.name = [net.name ‘ – Closed Loop’];
view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc)
% Multi-step Prediction
% Sometimes it is useful to simulate a network in open-loop form for as
% long as there is known output data, and then switch to closed-loop form
% to perform multistep prediction while providing only the external input.
% Here all but 5 timesteps of the input series and target series are used
% to simulate the network in open-loop form, taking advantage of the higher
% accuracy that providing the target series produces:
numTimesteps = size(x,2);
knownOutputTimesteps = 1:(numTimesteps-5);
predictOutputTimesteps = (numTimesteps-4):numTimesteps;
X1 = X(:,knownOutputTimesteps);
T1 = T(:,knownOutputTimesteps);
[x1,xio,aio] = preparets(net,X1,{},T1);
[y1,xfo,afo] = net(x1,xio,aio);
% Next the the network and its final states will be converted to
% closed-loop form to make five predictions with only the five inputs
% provided.
x2 = X(1,predictOutputTimesteps);
[netc,xic,aic] = closeloop(net,xfo,afo);
[y2,xfc,afc] = netc(x2,xic,aic);
multiStepPerformance = perform(net,T(1,predictOutputTimesteps),y2)
% Alternate predictions can be made for different values of x2, or further
% predictions can be made by continuing simulation with additional external
% inputs and the last closed-loop states xfc and afc.
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
nets = removedelay(net);
nets.name = [net.name ‘ – Predict One Step Ahead’];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
genFunction(net,’myNeuralNetworkFunction’);
y = myNeuralNetworkFunction(x,xi,ai);
end
if (false)
% Generate a matrix-only MATLAB function for neural network code
% generation with MATLAB Coder tools.
genFunction(net,’myNeuralNetworkFunction’,’MatrixOnly’,’yes’);
x1 = cell2mat(x(1,:));
x2 = cell2mat(x(2,:));
xi1 = cell2mat(xi(1,:));
xi2 = cell2mat(xi(2,:));
y = myNeuralNetworkFunction(x1,x2,xi1,xi2);
end
if (false)
% Generate a Simulink diagram for simulation or deployment with.
% Simulink Coder tools.
gensim(net);
end neural network, narx, input MATLAB Answers — New Questions