Unrecognized property Value for class Axes?
14 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have been trying to create a CT scan viewer through Matlab.
It is up and running, however, I am getting the error Unrecognized property Value for class Axes whenever I change and image.
It hightlights these two lines of code for me.
% Add listener to the slider to call a function when its value changes
addlistener(hSlider, 'Value', 'PostSet', @(src, event) updateImage(src, event, hAxes, dicomImages));
and
% Get the current value of the slider
sliderValue = round(get(hAxes.Parent.Children(2), 'Value')); % hAxes.Parent.Children(2) is the slider handle
Would anyone know where I went wrong?
0 个评论
回答(2 个)
Steven Lord
2024-8-2
Why do you believe that hAxes.Parent.Children(2) is the handle to your slider? I would not assume that the handles of the children of the axes's parent are always in order such that the second child is the slider.
0 个评论
dpb
2024-8-2
移动:dpb
2024-8-2
% Get the current value of the slider
sliderValue = round(get(hAxes.Parent.Children(2), 'Value')); % hAxes.Parent.Children(2) is the slider handle
Use the app-assigned handle to the slider (with your customized name if desired), not some attempt to find it by ad hoc code. Clearly by the error message, what you've actually returned is an axes object, NOT the slider, so it isn't what you think it is.
The standard callback function for the ValueChanged callback looks like:
% Value changed function: Slider
function SliderValueChanged(app, event)
value = app.Slider.Value;
... do whatever here ...
end
NOTA BENE the app.Slider handle that App Designer provides that is in the app struct created automgically for you. It will have your specific name for the slider in question there--use it.
That is a general precept for ALL controls; if you have similar other code for other controls, you need to fix them as well.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!