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

8 次查看(过去 30 天)
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
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
"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

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by