Setting the UserData property of a plot with max and min values

Hello, I am wanting to normalise a plot (between 0 and 1) with the option of undoing it.
This is my code to perform the normalisation.
ax=app.UIAxes;
[x,y] = getDataFromGraph(app,ax,1); % My function get get the XData & YData of a plot
mx=max(y(:)); mn=min(y(:));
y_normalized = normalize(y, 'range'); % This ensures max and min are 0 and 1
b=ax.Children; % b(1) is last object added to uiaxes
b(1).YData=y_normalized; % Neat way to change data without actully deleting it
% and retains all it properties such as colour
% Add the max and min values of the raw data to userdata
p=b(1) % Get last plot handle
p.UserData % See current value
set(p.UserData,mx) % Set mx
p.UserData % View agin to make sure its what we want
But this is leaving userdata as empty
Tag: ''
Type: 'line'
UserData: []
Visible: on
XData: [1.00 121.00 241.00 361.00 481.00 601.00 721.00 841.00 961.00 1081.00 1201.00 1321.00 1441.00 1561.00 1681.00 1801.00 1921.00 ] (1×136 double)
XDataMode: 'manual'
What am I doing wrong and how can I include both mx and mn in the userdata entry?

 採用された回答

Jason
Jason 2025 年 9 月 12 日

0 投票

Think I have the answer, this works
p.UserData % See current value
p.UserData=[mx,mn] % Set mx & mn
p.UserData

その他の回答 (1 件)

Stephen23
Stephen23 2025 年 9 月 12 日
編集済み: Stephen23 2025 年 9 月 12 日

0 投票

"What am I doing wrong and how can I include both mx and mn in the userdata entry?"
You made up some syntax. Better to use the syntax given in the SET documentation:
set(p,'UserData',mx)
or just assign directly to that property:
p.UserData = mx

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2024b

タグ

質問済み:

2025 年 9 月 12 日

コメント済み:

2025 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by