MATLAB: ‘Value’ must be a double scalar error

display valuedouble scalarerror

In my GUI I am trying to display some numerical values related to projectile motion. However, I keep getting the message, 'Value' must be a double scalar, when I try to display values for the range and the horizontal position at max height. Values for max height and flight time output just fine, and I cannot tell the difference between the type of values used in the equations. Furthermore, I have tried using the double command and the str2double command in attempts to change the value type, but neither are enabling me to display range or horizontal position values. What am I misunderstanding here?
Below is the relevant code:
gE = 9.81;
vix = v0*cosd(angle);
viy = v0*sind(angle);
hangtime1 = 2*viy/gE;
t1 = 0:hangtime1/50:hangtime1;
x1 = x0+vix.*t1;
maxheight1= y0 + (viy)^2./(2*gE);
xheight1 = x0 + vix.*(t1./2);
range1 = vix*t1;
r1 = double(range1);
% values I want to display; also want to include horizontal position, which is the variable xheight1
app.Hangtime.Value=hangtime1
app.MaxHeight.Value=maxheight1
app.Range.Value=r1
Thanks for your help out there!

Best Answer

Trying things at random (such as str2ouble) is not a good way to solve problems. The error message is clear, Value must be a scalar double, so clearly whatever you're passing is not a double or is not scalar. You are using double (and there's no need of the double(...) conversion which doesn't do anything), so the problem must be that the numbers are not scalar. Sure enough:
t1 = 0:hangtime1/50:hangtime1;
%...

range1 = vix*t1; %since t1 is an array, so is range1
r1 = double(range1); %doesn't do anything range1 is alreay double
%...
app.Range.Value=r1
You need to decide which value of range1 you want to pass to your control, or make sure range1 is scalar.