How to make graph instead of disp in command window for real time measurment
조회 수: 2 (최근 30일)
이전 댓글 표시
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
John D'Errico
2023년 9월 8일
편집: John D'Errico
2023년 9월 8일
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.
답변 (1개)
Constantino Carlos Reyes-Aldasoro
2023년 9월 11일
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
plot(Y3)
Hope that helps solve your problem
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!