Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Geoffrey Lo
Geoffrey Lo le 5 Juin 2020
Commenté : Geoffrey Lo le 6 Juin 2020
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)

Réponse acceptée

Ameer Hamza
Ameer Hamza le 5 Juin 2020
Something like this
plot(out.xout{8}.Data, out.yout{8}.Data)
  13 commentaires
Ameer Hamza
Ameer Hamza le 6 Juin 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.
Geoffrey Lo
Geoffrey Lo le 6 Juin 2020
Thanks a lot, it works now :)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by