I have a vector of integer elements, and most/all elements are in the thousands. When I look at the vector, some numbers are display in the normal format (eg, 5037) but some are displayed in scienfitic notation (eg 4.2890e+03). When I call the isinteger() function on my variable, it returns false. I think it is probably due to the way that some elements are stored in scientific notation, but I havent found any way, looking online, to force the variable to save all elements in the normal format. If I call isinteger(round()) on my variable, it still returns false. I also cannot typecast my vector to be eg. int16 (which I will get to in a minute).
The reason I need integer values is that some of these values will be used to index an array. I am using the "S = sparse(i,j,v,m,n,nz)" function, and the values m,n,nz all come from my variable. If I try to run it as is, where all of the values are actually integers but Matlab does not recognize them as such, I get the error message Every one of the elements should be integers, but it throws me an error regardless. Just so you can see what my variables are,
n = numel(x);
idx = 1:n;
x is my integer-valued double vector, and k is a particular element from x.
The documentation for sparse indicates that it shouldn't be problematic, as it says the first two terms (i,j aka idx, x) can be "Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical", the third term (v aka 1) can be "Data Types: double | logical", the fourth and fifth terms (m,n aka n,k) can be "Data Types: double" and the last term (nz aka n) can be "Data Types: double"
Based on the documentation, I don't understand why it won't accept my values -- it claims the type "double" is supported for every single input term.
If I try casting my vector, x, to be something else, like an int16, I get the error
even though the documentation claims that it accepts "single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical"
How can I resolve this? Is there any way to force all of the elements in my vector to be saved in the normal format and not scientific notation? Why do I get an error about input types when the documentation claims that data type is supported?
3 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838206
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838206
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838564
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838564
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838587
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/521780-troubles-with-data-types-integers-doubles-scientific-notation-and-type-casting#comment_838587
Sign in to comment.