How to fix " ''Value' must be a double scalar within the range of 'Limits'

Hello! Please help. My current code is:
%Value changed function: output_2
function output_2ValueChanged(app,event)
value_1=(app.input_1.Value);
maximum=(app.maximum.Value);
value_2=(app.input_2.Value);
amount= (value_1/maximum)*value_2;
final_val=amount*1000
app.Answer.Limits=[-100,100];
app.Answer.Value=final_val;
I kept getting an error with the " app.Answer.Vlue=final_val; " . Matlab says that 'value' must be a double scalar within range of limits. However, I tried to change the limits in the settings of each components in matlab gui, and I also put the limits on the codes itself but I am still ending up with the same error. What to do?

Answers (3)

You set the limits to [-100,100] and then try to set a value equal to amount*1000.
We don't know what values you are using, but apparently the resulting value of final_val is <-100 or >100.
Use the debugger to examine the problem:
dbstop if error
Run the code again until Matlab stops at the error. Now check the value of final_val. Is it inside the limits? Is is a scalar double? Whatare the limits? What is app.Answer?
If your final_val is not double type, you may need to cast it into double before assign to value.
Not sure if this is considered a bug of Matlab. I'm also struggling with this issue when I'm trying to assign a single precision into Value field.

Categories

Asked:

on 7 Feb 2022

Answered:

on 5 Jul 2022

Community Treasure Hunt

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

Start Hunting!