Why can't I store this many values In line

2 views (last 30 days)
So I know I could do this with a loop, but since I'm already inside a nested loop for this I'm trying to minimize how nested things get. The problem occurs without the loops so I'll just provide an example of the point of failure I'm encountering. Here are the variables and their relationship to one another. Depletion is a large matrix with data values in it.
jj = 1;
i = 1;
v1 = Depletion(2*jj-1,i)
v2 = Depletion(2*jj,i)
v3 = max([MatDeni(v1,jj) MatDeni(v2,jj)])
v4 = min([MatDeni(v1,jj) MatDeni(v2,jj)])
v5 = mean([MatDeni(v1,jj) MatDeni(v2,jj)])
v6 = min(MatDeni(v1:v2,jj))
v7 = Ledge + int16((v2 - v1)/2)
When I run this the output I get is:
v1 =
1086
v2 =
1115
v3 =
5.7254e+05
v4 =
4.4962e+05
v5 =
5.1108e+05
v6 =
23322
v7 =
1101
Now I try to put these values into a vector. When I do just v1-v6 everything is fine
[v1 v2 v3 v4 v5 v6]
returns
ans =
1086 1115 5.7254e+05 4.4962e+05 5.1108e+05 23322
however when I do v1-v7,
[v1 v2 v3 v4 v5 v6 v7]
returns
ans =
1086 1115 32767 32767 32767 23322 1101
It seems the values in scientific notation have been changed to some apparently arbitrary value of 32767. Maybe I should just change the format that the values get stored so they're not scientific notation, but this seems like strange behavior.

Accepted Answer

James Tursa
James Tursa on 3 Mar 2015
Edited: James Tursa on 3 Mar 2015
Since v7 is an integer type (int16), when you combine it with doubles in concatenation [ ], the doubles get converted to int16. To get around this you need to convert v7 to a double first. E.g.,
[v1 v2 v3 v4 v5 v6 double(v7)]
The 32767 you are seeing is simply the double values larger than the largest int16 (32767) being clipped at that value.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!