Plotting simplenarx_dataset

12 次查看(过去 30 天)
Gibbov
Gibbov 2023-8-24
评论: Voss 2023-8-26
I tried to plot the simplenarx_dataset but it is coming up blank (i get a graph with x and y axis but no data in it). Can anyone help me?
load simplenarx_dataset;
data = simplenarx_dataset;
figure; plot(data{1});
hold on;
plot(data{2});
xlabel('Time');
ylabel('Value');
legend('Input', 'Output');
  3 个评论
Gibbov
Gibbov 2023-8-24
It is built-in to MATLAB as far as I know. NARX dataset is a 1x100 cell array of scalar values, which represent an 100 timestep time-series in addition to a 1x100 cell array of scalar values representing a 100 timestep time-series for the prediction.
If you type "load simplenarx_dataset;" into MATLAB it creates something, without the need for a file from me.
Dyuman Joshi
Dyuman Joshi 2023-8-24
I see, I was not aware of this particular dataset.

请先登录,再进行评论。

采纳的回答

Voss
Voss 2023-8-24
simplenarx_dataset.mat is a mat-file; simplenarx_dataset.m is a function m-file.
When you load simplenarx_dataset, you load the variables contained in the mat-file into the workspace. These variables are simplenarxInputs and simplenarxTargets.
load simplenarx_dataset
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char simplenarxInputs 1x100 11200 cell simplenarxTargets 1x100 11200 cell
When you call the function simplenarx_dataset, you get up to two outputs, which are the same two variables contained in the mat-file.
[inputs,targets] = simplenarx_dataset();
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char inputs 1x100 11200 cell simplenarxInputs 1x100 11200 cell simplenarxTargets 1x100 11200 cell targets 1x100 11200 cell
isequal(inputs,simplenarxInputs) % the first output from simplenarx_dataset() is simplenarxInputs from the mat-file
ans = logical
1
isequal(targets,simplenarxTargets) % the second output from simplenarx_dataset() is simplenarxTargets from the mat-file
ans = logical
1
You can inspect the contents of the m-file to see that it is in fact loading the mat-file and returning the requested variables (scroll down to the end):
type simplenarx_dataset.m
function [inputs,targets] = simplenarx_dataset %SIMPLENARX_DATASET Simple time-series prediction dataset % % Input-output time series problems consist of predicting the next value % of one time-series given another time-series. Past values of both series % (for best accuracy), or only one of the series (for a simpler system) % may be used to predict the target series. % % This dataset can be used to demonstrate how a neural network can be % trained to make predictions. % % LOAD simplenarx_dataset.MAT loads these two variables: % % simplenarxInputs - a 1x100 cell array of scalar values representing % a 100 timestep time-series. % % simplenarxTargets - a 1x100 cell array of scalar values representing % a 100 timestep time-series to be predicted. % % [X,T] = simplenarx_dataset loads the inputs and targets into % variables of your own choosing. % % You can import this example data set from within the Neural Net Time % Series app. Open the app by calling ntstool. % % Here is how to design a neural network that predicts the target series % from past values of inputs and targets. See narxnet for more details. % % [X,T] = simplenarx_dataset; % net = narxnet(1:2,1:2,10); % [Xs,Xi,Ai,Ts] = preparets(net,X,{},T); % net = train(net,Xs,Ts,Xi,Ai); % view(net) % Y = net(Xs,Xi,Ai) % plotresponse(Ts,Y) % % Here is how to design a neural network that predicts the target series % from only using past values of inputs. See timedelaynet for details. % % net = timedelaynet(1:2,10); % [Xs,Xi,Ai,Ts] = preparets(net,X,T); % net = train(net,Xs,Ts,Xi,Ai); % % Here is how to design a neural network that predicts the targets series % only using past values of the target series. See narnet for details. % % net = narnet(1:2,10); % [Xs,Xi,Ai,Ts] = preparets(net,{},{},T); % net = train(net,X,T,Xi,Ai); % % See also NTSTOOL, NARXNET, TIMEDELAYNET, NARNET, PREPARETS, NNDATASETS. % Copyright 2010-2021 The MathWorks, Inc. load simplenarx_dataset inputs = simplenarxInputs; targets = simplenarxTargets;
That's all to say that, in your code, the load is unnecessary because you don't do anything with the loaded variables simplenarxInputs and simplenarxTargets. Instead you are calling simplenarx_dataset.m on the next line, with one output, which makes your variable data have the value of simplenarxInputs from the mat-file, which is the first output of the function simplenarx_dataset.
Now for the question you asked: why do plot(data{1}) and plot(data{2}) not produce any visible result?
That's because data{1} and data{2} are each scalars, i.e., the cells in positions 1 and 2 (in fact in all positions) of data each contain only a single value, so you are plotting only single points. You cannot see a single point unless you use a data marker.
figure;
data = simplenarx_dataset();
plot(data{1},'o'); % marker 'o'
hold on;
plot(data{2},'x'); % marker 'x'
xlabel('Time');
ylabel('Value');
legend('Input', 'Output');
Maybe you want to get both outputs from simplenarx_dataset(), and plot them against each other.
figure
[data,targets] = simplenarx_dataset();
data = [data{:}];
targets = [targets{:}];
plot(data,targets,'.')
  4 个评论
Gibbov
Gibbov 2023-8-26
Also, how would i connect the dots (with a line between them ) on the graph to create a line between each '.'?
Voss
Voss 2023-8-26
plot(data,targets,'.-')

请先登录,再进行评论。

更多回答(1 个)

Dyuman Joshi
Dyuman Joshi 2023-8-24
simplenarx_dataset is a 1x100 cell array, with each cell element containing a numerica scalar.
load simplenarx_dataset;
data = simplenarx_dataset
data = 1×100 cell array
Columns 1 through 14 {[0.3112]} {[0.5285]} {[0.1656]} {[0.6020]} {[0.2630]} {[0.6541]} {[0.6892]} {[0.7482]} {[0.4505]} {[0.0838]} {[0.2290]} {[0.9133]} {[0.1524]} {[0.8258]} Columns 15 through 28 {[0.5383]} {[0.9961]} {[0.0782]} {[0.4427]} {[0.1067]} {[0.9619]} {[0.0046]} {[0.7749]} {[0.8173]} {[0.8687]} {[0.0844]} {[0.3998]} {[0.2599]} {[0.8001]} Columns 29 through 42 {[0.4314]} {[0.9106]} {[0.1818]} {[0.2638]} {[0.1455]} {[0.1361]} {[0.8693]} {[0.5797]} {[0.5499]} {[0.1450]} {[0.8530]} {[0.6221]} {[0.3510]} {[0.5132]} Columns 43 through 56 {[0.4018]} {[0.0760]} {[0.2399]} {[0.1233]} {[0.1839]} {[0.2400]} {[0.4173]} {[0.0497]} {[0.9027]} {[0.9448]} {[0.4909]} {[0.4893]} {[0.3377]} {[0.9001]} Columns 57 through 70 {[0.3692]} {[0.1112]} {[0.7803]} {[0.3897]} {[0.2417]} {[0.4039]} {[0.0965]} {[0.1320]} {[0.9421]} {[0.9561]} {[0.5752]} {[0.0598]} {[0.2348]} {[0.3532]} Columns 71 through 84 {[0.8212]} {[0.0154]} {[0.0430]} {[0.1690]} {[0.6491]} {[0.7317]} {[0.6477]} {[0.4509]} {[0.5470]} {[0.2963]} {[0.7447]} {[0.1890]} {[0.6868]} {[0.1835]} Columns 85 through 98 {[0.3685]} {[0.6256]} {[0.7802]} {[0.0811]} {[0.9294]} {[0.7757]} {[0.4868]} {[0.4359]} {[0.4468]} {[0.3063]} {[0.5085]} {[0.5108]} {[0.8176]} {[0.7948]} Columns 99 through 100 {[0.6443]} {[0.3786]}
When plotting a numeric scalar via plot, you will need to specify a marker to show the point on the figure -
figure;
plot(data{1},'r*');
hold on;
plot(data{2},'bo');
xlabel('Time');
ylabel('Value');
legend('Input', 'Output');
You can also use scatter to show scalar points on figure, which does not require markers input for that.
  1 个评论
Gibbov
Gibbov 2023-8-26
Thanks. I need to plot all of the data at the same time, not just one bit of data.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by