How to plot data in Matlab from workspace (Simulink)

121 ビュー (過去 30 日間)
Jimmy Neutron
Jimmy Neutron 2020 年 11 月 12 日
コメント済み: Ameer Hamza 2020 年 11 月 13 日
Dear all,
I am currently trying to create a real-time scatter like plot (I want to plot individual points or markers, with which I will later do calculations (finding the mean etc)). My current method of trying is to send the values I have in Simulink to Matlab using the "to Workspace" blocks that I renamed x and y:
I have created a test. file, which includes the following lines:
x = out.x.data;
y = out.y.data;
scatter(x,y)
drawnow
pause(.5)
Unfortnately, nothing is working. I am trying to update the x and y coordinates and plot these two points, but cannot manage it. Can someone please help me?

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
You have written 'get' instead of 'out'
x = get.x.data;
%^ replace it with out
Apart from that, your code is correct.
  2 件のコメント
Jimmy Neutron
Jimmy Neutron 2020 年 11 月 12 日
my bad, that was a typo. It still does not work unfortunately. I am not stopping the simulink and that m ight be causing problems, but Ii want to update the graph after every 0.3 seconds...
Ameer Hamza
Ameer Hamza 2020 年 11 月 13 日
So you are trying to plot the data while simulink is running? In that case, you will need to use event listeners. For example see this: https://blogs.mathworks.com/simulink/2013/01/25/accessing-block-data-during-a-simulation/

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


Sara Nadeau
Sara Nadeau 2020 年 11 月 12 日
Hello,
I believe that the data logged to the workspace is only available after you pause a simulation and when a simulation completes.
If you're working with a version of Simulink that is R2018b or later, you can use a data access callback function to plot data during the simulation: Access Data in a MATLAB Function During Simulation.
Hope this helps!

カテゴリ

Help Center および File ExchangeScopes and Data Logging についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by