How to make graph instead of disp in command window for real time measurment

2 Ansichten (letzte 30 Tage)
Hi
I have the following code for timeseries measurment and i want to obtain the results in format of graph instead of display in command window
I want basically to replace the line disp(Y2) with graph . x axis is with time and y axis with power
Herein the code
clear all;
close all;
clc
t = xlsread('Forecasting by ML with Real_Time/power_consumption.xlsx')';
t = num2cell(t);
net = narnet(1:2,10);
[X,Xi,Ai,T] = preparets(net,{},{},t);
net = train(net,X,T,Xi,Ai);
view(net)
Y = net(X,Xi,Ai);
perf = perform(net,Y,T);
[Xo,Xio,Aio,To] = preparets(net,{},{},t);
[Y1,Xfo,Afo] = net(Xo,Xio,Aio);
[netc,Xic,Aic] = closeloop(net,Xfo,Afo);
view(netc)
[Y2,Xfc,Afc] = netc(cell(0,100),Xic,Aic);
[sysName,netName] = gensim(netc,'Name','nnarnetmodel','InputMode','Workspace',...
'OutputMode','WorkSpace');
setsiminit(sysName,netName,netc,Xic,Aic,1); % here we set initial states for the model
save_system('nnarnetmodel.slx') % here we save the simulink model
intime = length(t); % this is the initial time forecast. as you know the first forecast point is after the last time stamp in our training data. so the initial time is end of the training time or end of the data time
%N = input('how many step to be predicted ? ');
N = 1;
continuing = 'y';
while continuing == 'y' % this while loop is running the simulink model and each time sets the last states as initial states for the next forecast
% Note: It will ask the number of forecast points each time and it will
% ask whther you want to continue prediction or not.. the results will
% be shown in simulink
%N = input('how many step to be predicted ? ');
%N = 2;
endtime = intime + N; % this is the end time for forecast
% note: here to make sure the code works correct. i did prediction in
% both simulink and hee in script and compared the values to make sure
% the initial values are set correctly in each loop
[Y2,Xfc,Afc] = netc(cell(0,N),Xic,Aic); % this is the script forecast by calling netc model
setsiminit(sysName,netName,netc,Xic,Aic,1); % here we set initial states in each loop in simulink model
set_param(getActiveConfigSet(sysName),...
'StartTime',num2str(intime),'StopTime',num2str(endtime-1),'ReturnWorkspaceOutputs','on'); % we also set the forecast time in simulink model
r = sim('nnarnetmodel.slx'); % here we run simulink model
disp(Y2) % this shows results of script
intime = endtime + 1; % the initial time of next step will be end time of this step
Xic = Xfc; % setting initial values of model for next forecast
Aic = Afc;
pause(60); % this
end
  1 Kommentar
John D'Errico
John D'Errico am 8 Sep. 2023
Bearbeitet: John D'Errico am 8 Sep. 2023
You cannot make a figure appear in the command window. Perhaps I am reading your question wrong. You can generate a figure that will contain your plot. Plot will do that, or any of god knows how many other tools. But it will be a separate figure.
Or, you can build a Live Script, which would allow for embedded graphics in the result.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Constantino Carlos Reyes-Aldasoro
disp will display a value or text on the command line, if what you want is a graph, then you will need to save that value into a variable and when you finish display, e.g.,
for k=1:30
Y2 = sin (k);
disp(Y2)
Y3(k) = Y2;
end
0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 0.9894 0.4121 -0.5440 -1.0000 -0.5366 0.4202 0.9906 0.6503 -0.2879 -0.9614 -0.7510 0.1499 0.9129 0.8367 -0.0089 -0.8462 -0.9056 -0.1324 0.7626 0.9564 0.2709 -0.6636 -0.9880
plot(Y3)
Hope that helps solve your problem

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by