필터 지우기
필터 지우기

I keep getting a “cannot convert double value “…” to a handle. Does anybody know how I can fix my code in order for this to go away

조회 수: 62 (최근 30일)
DOES ANYBODY KNOW HOW TO FIX THIS? I keep getting a “cannot convert double value “…” to a handle. Does anybody know how I can fix my code in order for this to go away?
  댓글 수: 8
Zalif
Zalif 2024년 4월 26일

and this is the code for the app where the summarized error pops up

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

답변 (2개)

Walter Roberson
Walter Roberson 2024년 4월 26일
Historically, up to R2014a, it was the case that graphics handles were returned as double precision numbers. This allowed constructions such as
h(1) = plot(x, y);
h(2) = x(1);
h(3) = x(end);
However, as of R2014b, graphics routines return handles to graphics.
In the above example, the first statement would initialize h as being an array of graphics handles, containing the handle to a chart line object. The second statement would then try to convert the value in x(1) into a graphics handle. If x(1) just happened to be 1 then the conversion would probably succeed, becoming a handle to figure 1. Then the third statement would try to convert x(end) to a handle, which would probably fail because no figure numbered the same as x(end) probably exists.
If you have code that mixes graphics handles and numeric objects, then you need to separate them.

Steven Lord
Steven Lord 2024년 4월 26일
Seeing the screenshot of the code helped me understand the problem.
Note in your multipulcationButtonPushed method (you misspelled multiplication BTW) you retrieve the values from the edit field by accessing their Value properties to create the variables a and b. But when you attempt to populate the answer field on the last line of that method, you try to assign the variable k into the AnswerEditField property of the app rather than the Value property of the AnswerEditField property of the app. Try:
function multipulcationButtonPushed(app, event)
a = app.FirstNumberEditField.Value;
b = app.SecondNumberEditField.Value;
k = a*b;
app.AnswerEditField.Value = k;
end
You have the same problem in your other arithmetic methods.

Community Treasure Hunt

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

Start Hunting!

Translated by