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

19 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 5 Jun. 2020
Something like this
plot(out.xout{8}.Data, out.yout{8}.Data)
  13 Kommentare
Ameer Hamza
Ameer Hamza am 6 Jun. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by