vpa adding ".0" to the end

1 visualización (últimos 30 días)
Jacob Kelley
Jacob Kelley el 14 de Nov. de 2019
Respondida: Walter Roberson el 14 de Nov. de 2019
So I am needing to use vpa(#,d) for a very large number on the magnitude of 1x10^(250). I've figured out how to use it but for some reason it adds .0 to the end which I can't have.
example:
n = vpa('3546',32)
disp(n)
output:
3546.0
The reason I can't have the .0 is because I am constructing a sequence that depends on if there are any 0s in the number and the ".0" at the end makes it think it always has a 0 in the number
N = string(n);
strlength(N)
N = convertStringsToChars(N);
for i = 1:strlength(N)
if N(i) == '0' || N(i) == '1' || N(i) == '5'
disp('N(i) = 0,1,5')
skpchk = 'True';
break;
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Nov. de 2019
https://www.mathworks.com/help/matlab/matlab_prog/searching-and-replacing.html
regexprep can also be used.
I can also offer you code for r2019a and later that converts all floating point software numbers into rationals. In the case of integers with .0 that would construct the integers. However there is the issue that vpa shows you a truncated value that is not necessarily exactly what is stored, so if the numbers do not convert exactly to integers then they might not come out as expected. But the code could easily be adapted to round before converting to rational.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by