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
33 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 26 Apr 2024
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.
0 Comments
Steven Lord
on 26 Apr 2024
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!