How do I plot a X-Y graph in matlab with data using "to workspace" block

8 次查看(过去 30 天)
I have 2 simulations and I took the data from both simulations and the data I wants is at out.xout{8} and out.yout{8} as a 1x1 double timeseries. How do I plot a X-Y graph out of these data? The code for retrieving data from "to workspace" block is as below:
clear all
close all
clc
%open system
open_system('circlex_ds');
%set parameters for x to workspace
set_param('circlex_ds/To Workspace',...
'VariableName','x')
%output the simulation results
out = sim('circlex_ds');
%plot function
figure()
plot(out.x)
x=out.xout{8};
%open system
open_system('circley_ds');
%set parameters for y to workspaae and for file
set_param('circley_ds/To Workspace',...
'VariableName','y')
%output the simulation results
out = sim('circley_ds');
%plot function
figure()
plot(out.y)

采纳的回答

Ameer Hamza
Ameer Hamza 2020-6-5
Something like this
plot(out.xout{8}.Data, out.yout{8}.Data)
  13 个评论
Ameer Hamza
Ameer Hamza 2020-6-6
Oh! I forgot to consider that the time vector might not be equally spaced. Following will work
Time = linspace(0, 7, 1000);
x_interp = interp1(out1.x.Time, out1.x.Data, Time);
y_interp = interp1(out2.y.Time, out2.y.Data, Time);
plot(x_interp, y_interp)
it uses out1 and out2 you shared preiously.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by