Plotting simplenarx_dataset
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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
isequal(inputs,simplenarxInputs) % the first output from simplenarx_dataset() is simplenarxInputs from the mat-file
isequal(targets,simplenarxTargets) % the second output from simplenarx_dataset() is simplenarxTargets from the mat-file
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
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,'.')
更多回答(1 个)
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


