Plotting two signals referenced with each other

7 ビュー (過去 30 日間)
Moudrek Osmani
Moudrek Osmani 2021 年 2 月 24 日
回答済み: Satwik 2024 年 5 月 23 日
Hi,
Assuming I have two time-based signals (where each X-axis corresponds to the time sample), as shown below:
Under same powergui option (Discrete: 5e-06) is there any way that I can plot the two signals with reference to each other (i.e. X-axis for first signal, Y-axis for the second)? the XY plotter in this case does not work.
Thanks

回答 (1 件)

Satwik
Satwik 2024 年 5 月 23 日
Hi,
The functionality of plotting two signals against each other under the powergui simulation is not provided by any built-in function. Although, you can achieve the desired result using MATLAB scripting as a workaround. This method involves logging the signals of interest during simulation and then plotting them against each other after the simulation has completed. You may follow the steps given below:
  1. Ensure that the signals you want to plot against each other are being logged. In Simulink, you can use the To Workspace block or the Signal Loggingfeature to save your signals to the MATLAB workspace. Make sure both signals are logged at the same sample rate.
  2. Run your simulation.
  3. After the simulation completes, the signals will be available in the MATLAB workspace. You can then use MATLAB commands to plot these signals against each other.
% Assume your signals are logged as simOut with the names 'vOut' and 'iOut'.
% Load the signals
xData = simOut.get('vOut').signals.values;
yData = simOut.get('iOut').signals.values;
% Ensure both signals have the same length.
minLength = min(length(xData), length(yData));
xData = xData(1:minLength);
yData = yData(1:minLength);
% Plot the signals against each other.
figure;
plot(xData, yData);
xlabel('vOut');
ylabel('iOut');
title('vOut vs. iOut');
grid on;
This script assumes you have used the Simulink logging feature to log your signals. If you used ‘To Workspace’ blocks, your signals would be directly in the workspace with the variable names you specified, and you can modify the script accordingly.
For more information on the process of ‘Signal Logging’ and the ‘plot’ function you may refer to this documentation given below:
Hope this helps!

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by