How to normalize output data for a plot

196 ビュー (過去 30 日間)
Giovanni Ponce
Giovanni Ponce 2022 年 6 月 29 日
コメント済み: Giovanni Ponce 2022 年 7 月 13 日
I want to normalize the the y-axis of a plot. The current limits for the graph are set from 0 to 30 on the y-axis, how would I normalize the output data of the simulink model being 'sim_data.Pd'? Could it be possible to use the Normalize function for this?
  2 件のコメント
Jonas
Jonas 2022 年 6 月 29 日
what do you mean with Normalization? You want values only between 0 and 1? You want to see in the plot these normalized values?
Giovanni Ponce
Giovanni Ponce 2022 年 6 月 29 日
I want to normalize the all the datasets from 0 to 1 that are going to be plotted, so only the y-axis(datasets) are normalized.

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

採用された回答

NIVEDITA MAJEE
NIVEDITA MAJEE 2022 年 6 月 29 日
Hi Giovanni,
You can use the ‘normalize’ function to normalize the output data. In the line 71 you can replace it with
plot(t_sim, normalize(sim_data.Pd, 'range'), 'r', 'LineWidth', 1.2);
The “normalize(sim_data.Pd, 'range')” will normalize your data between 0 and 1.
I have used the piece of code in the attached screenshot, and instead of simulated datapoints I have used “rand function” to generate random numbers to be used later for plotting.
Here is the code and later you can also find the generated plot with the code:
sim_data = 20*rand(10,2); %using rand function to generate a 10x2 matrix of random numbers between 0 and 20
t_sim = linspace(0,1,10); %creating a vector with 10 evenly spaced values between 0 to 1
figure;
set(gca, 'FontSize', 10);
hold on;
grid on;
box on;
plot(t_sim, normalize(sim_data(:,1), 'range'), 'b', 'LineWidth', 1.2);
plot(t_sim, normalize(sim_data(:,2), 'range'), 'r', 'LineWidth', 1.2);
ylabel('Power (MW)')
xlabel({'Time (hour)'})
legend('Pset', 'Pd', 'Orientation', 'horizontal', 'location', 'southwest')
title('Dispatch power');
xlim([0 max(t_sim)])
For more information on the normalize function, refer to the following link:
  2 件のコメント
Giovanni Ponce
Giovanni Ponce 2022 年 6 月 30 日
You are a live saver! Thank you
Giovanni Ponce
Giovanni Ponce 2022 年 7 月 13 日
I have another question, If I would want to normilize the actual data instead of just the y axis, how would I make that possible?

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

その他の回答 (1 件)

Aman Banthia
Aman Banthia 2022 年 6 月 29 日
Hi Giovanni,
Seems like you can normalize the data using the normalize function. But there is no method named 'sim_data' there are a fixed set of data you can normalize using this function.
Refer to the following MATLAB document to know about the Normalization Methods of the normalize function:

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by