'Value' must be a double scalar error?
48 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Guillaume
on 3 Feb 2019
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.
2 Comments
Eduar Yesid
on 22 Jul 2023
por lo que se puede observar el error se da porque el valor de la variable T1 es un error, es decir es como si estubieras dividiendo 1/0. Para solucionar el error debes asegurarte que el valor de T1 es un numero valido
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!