フィルターのクリア

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

8 ビュー (過去 30 日間)
Geoffrey Lo
Geoffrey Lo 2020 年 6 月 5 日
コメント済み: Geoffrey Lo 2020 年 6 月 6 日
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.
Geoffrey Lo
Geoffrey Lo 2020 年 6 月 6 日
Thanks a lot, it works now :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by