필터 지우기
필터 지우기

Use uieditfiel​d.ValueCha​ngedFcn to change uieditfield.value by same amount

조회 수: 12 (최근 30일)
I have a gui that contains a uieditfield component. The editfield changes the orientation of a detector by the uieditfield.Value amount. Many times I wish to change the field by increments of 1. For example, I enter a value, say 1 into the edit field box. The next time I want to move the detector by the same amount. When I type in 1 to the uieditfield box, the detector does not move, however, if I type in 1.1 then the detector moves. I believe that this behavior is connected to the uieditfield method ValueChangedFcn. I am using uieditfield.ValueChangedFcn as a callback to move the detector. My question is:
How can I change the orientation of my detector by using constant increments? Should I use a different ui component to get the behavior I need? Is the problem actually in using uieditfield.ValueChangedFcn?

채택된 답변

John Williams
John Williams 2022년 3월 11일
I found the solution. I needed to set the uieditfield.Value to a different number after I had used the value to change the orientation of my detector. I chose zero as I am unlikely to edit the field with a new value of zero.

추가 답변 (1개)

Voss
Voss 2022년 3월 11일
It sounds like what's going on is that the ValueChangedFcn does not execute when the uieditfield's Value does not change. So you need a way to update the detector orientation when the detector orientation increment is not changing.
You may consider putting an additional component in your UI, say a uibutton whose ButtonPushedFcn increments the orientation of the detector by the amount given in the uieditfield's Value.
  댓글 수: 3
Voss
Voss 2022년 3월 11일
I think setting uieditfield.Value to zero after getting the new value would work.
But you may want to rethink your code's structure a little bit, because you need a function to update the detector orientation, say updateDetectorOrientation(), that is not tied only to the uieditfield's ValueChangedFcn. I mean, updateDetectorOrientation() can be called from the uieditfield's ValueChangedFcn, but it also needs to be called any time the detector orientation needs to update for any reason.
John Williams
John Williams 2022년 3월 11일
I would love to change my code's structure but I don't really know how to make it better. I am new to Matlab and new to GUI programming but old to programming. In fact, I am a scientist and not really a computer programmer at all. As such, I have never really understood the structure behind GUI programming. I have no reference to see how to do it more effectively.
As of right now, I am calling the updateDetectorOrientation function in three different places, one when I set up the GUI, one when I rotate clockwise and one when I rotate counterclockwise; none of these are callbacks. In the rotate clockwise and counterclockwise functions updateDetectorOrientation is called by the callback function. The whole program is working but my feeling is that it is on the brink of a crash(i.e. anytime someone does something different from what I expected). Do you have a source for properly programming gui programs? Something related to Matlab? I find that the Matlab help stuff is not very useful. Thanks for your insights.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by