Java slider not Responding
이전 댓글 표시
The slider is saved as S.sl1 and I convert it to sl1 and output it. I then convert it to a java slider in another function with :
jScrollBar = findjobj(sl1);
jScrollBar.AdjustmentValueChangedCallback = @updateplot;
Then the call back function is:
function updateplot(sl1,ht,funcNum)
x = get(sl1,'Value');
Beam.Location = x;
switch funcNum
case funcNum == 1
y = Cantilieverd_Point(Beam);
set(ht,'ydata',y);
drawnow;
case funcNum == 2
y = Simple_Point(Beam);
set(ht,'ydata',y);
drawnow;
end
end
Where ht is the plot that is being updated and the ' y = ' is another function which creates the y value. When I run this it does not return an error, but it also does absolutely nothing to the graph. I want it to continuously update the graph based off of the slider value.
댓글 수: 5
Matt Fig
2012년 12월 12일
Just a note:
When you post code that relies on a FEX file, you should state that and give a link so people don't try to copy/paste your code only to get an error...
Matt Fig
2012년 12월 12일
Also, were you not able to make the addlistener code work?
Malcolm Lidierth
2012년 12월 12일
How does updateplot know the value of funcNum? ht is an EventData object - it has no 'ydata' property. Is this a slider or a scrollBar.
The callback can not be being called - or you would see errors.
A more complete code example is needed to be more helpful.
Lawson Hoover
2012년 12월 12일
Malcolm Lidierth
2012년 12월 12일
편집: Malcolm Lidierth
2012년 12월 12일
@Lawson That is a vital bit of info. The callback is evaluated once, throws an exception and gets removed by MATLAB. You need something like:
jScrollBar.AdjustmentValueChangedCallback = {@updateplot, ht, funcNum};
The callback should then be declared as:
function updateplot(sl1,EvenData, ht, funcNum)
sl1 and EventData are added automatically to the inputs by MATLAB>
답변 (1개)
Jan
2012년 12월 12일
There are several problems in your code:
1. Here the callback is defined with no inputs:
jScrollBar.AdjustmentValueChangedCallback = @updateplot;
But in the definition of the callback function, 3 inputs are required.
2. Look at the documentation of switch/case again. The term "funcNum==1" is evaluated to either true or false, but you want to switch for the value 1 or 2. Therefore you need:
switch funcNum
case 1 % Not "funcNum == 1"
...
I suggest not to use a Java slider, but the standard Matlab sliders. You cann attach a listener to them also: http://www.mathworks.com/support/solutions/en/data/1-3SR0YI/index.html?product=ML&solution=1-3SR0YI
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!