Help urgent ! Error while evaluating uicontrol Callback

조회 수: 215 (최근 30일)
andrei cosmin
andrei cosmin 2017년 5월 25일
댓글: Walter Roberson 2020년 5월 9일
Hi ! Any idea why this is happening and how to fix it?
Thanks,
  댓글 수: 3
andrei cosmin
andrei cosmin 2017년 5월 25일
This is the code. Can you help me solve the error? :( I will be grateful, thank you!

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 28일
Your code relies upon Legacy Arduino, suitable for MATLAB R2011a to R2013b only. It calls upon install_arduino which is defined by that particular support package, and it uses pinMode(), which was replaced, as I discuss in https://www.mathworks.com/matlabcentral/answers/304583-no-appropriate-method-property-or-field-pinmode-for-class-arduino#answer_236196
Your code is not suitable for demonstrating any reasonably current version of MATLAB: it will fail for R2014a or later.
In the version range that it works for, your code would crash at the location it does if you have not first clicked on the STABILESTE CONEXIUENEA button to initialize the arduino connection. Your code will also have problems if you do not click on START as well.
Your code will fail when you click on START if you are not using a PC, as the code expects to be able to access the winvideo video adapter.
  댓글 수: 5
andrei cosmin
andrei cosmin 2017년 5월 29일
Thank you very much for the answer! I solved the problem!
Robert Adam
Robert Adam 2018년 4월 17일
poti sa imi spui si mie care era problema si de ce aparea aceasta eroare?..multumesc anticipat!

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

추가 답변 (2개)

Guillaume
Guillaume 2017년 5월 25일
편집: Guillaume 2017년 5월 25일
As per Stephen's comment, you have a bug with your global variables. Either, your callback is being executed before whichever function is supposed to set a to the correct value had a chance to do so, or some function has changed the global a to an invalid value. Either way, when the callback is executed a is not yet/no longer a structure and you get your error.
As Stephen said, globals are a bad idea, precisely for this reason. It's very difficult to track what happens to them; any function can modify their value. It's also difficult to make sure that they're initialised in the right order, particularly when you use asynchronous functions such as callback.
You now have two options:
  • go over the whole of your program and check the flow to see when a is supposed to be set to the correct value (can be anywhere in the code), see where it is being changed (again can be anywhere) and make sure that this always happen before there's a chance your callback is called.
  • radically modify your code to use recommended practices such as gui handles
Neither is going to be quick. The second approach would ultimately serve you better.
  댓글 수: 5
Jan
Jan 2017년 5월 27일
@andrei cosmin: What do you expect me to do with your code? Do you think that I will edit and fix it for you? You think that your problem is urgent, becasue you have to "teach it" in two weeks? Then this is ther perfect moment to learn how to use clean programming techniques and avoid globals strictly.
If I fix your code, wou will miss the chance to learn how to do this. This would not help you to teach it or use it for teaching or what ever your job is.
It would be unprofessional to fix your code. Working inside ugly code written by others is a brown-field project. If there is no really good reason (masured in ten thousands of dollars or months of work), the best method to cleaning up a brown-field project is to delete the code and re-write it from scratch. Fiddeling in failing code is extremely prone to errors. Guessing the intention of other ones code is expected to fail. Especially globals are such ugly, that I would not even fix my own code, if it suffers from them.
The best advice I can give you is:
Remove the globals and replace them by fields of the handles struct. Search in the forum for "share data between callbacks" - the problem is discussed daily. And after you have implemented this, you will be a nice step closer to beeing a Matlab master! :-)
Alternatively you can ask someone to fix your code professionally. This will most likely include, that the original code is deleted and re-written from scratch. And of course such a service must include a salary. A good professional programmer might write + document + test this in an hour and costs 160 $ per hour. A beginner might need 8 hours at a price of 20 $ per hour. As usual the actual work will take twice as long as estimated (measured in time and money), even if you take this rule into consideration.
Walter Roberson
Walter Roberson 2017년 5월 27일
Why do your uicontrol style text have KeyPressFcn set to '%automatic' ??

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


ismail tas
ismail tas 2020년 5월 9일
ı have similer problem in Matlab Gui . I want to desing calculator. Every toggle button dont have any problem but answer button have problem and it gives Error while evaluating UIControl Callback.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 9일
You should start a new Question for this, and you should include your code and the .fig, and a complete copy of the error message.

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by