how to consider only the integer part discarding the exponent part

2 visualizaciones (últimos 30 días)
ANUSAYA SWAIN
ANUSAYA SWAIN el 2 de Jun. de 2023
Editada: Star Strider el 2 de Jun. de 2023
Suppose i have a= [1 23 56]*10^(-9);
i want to acccess only the integer part that is 1 23 and 56.
i want to find the max(a). That is the output should be 56.

Respuestas (2)

Pramil
Pramil el 2 de Jun. de 2023
Editada: Pramil el 2 de Jun. de 2023
What you can do is multiply "a" with 10^9 first and then proceed to find max(a). Like this :
a = [1 23 56]*10^(-9); % given array
a_int = int64(a*10^9); % convert to integer array
max_a = max(a_int); % find maximum value
disp(max_a);
56

Star Strider
Star Strider el 2 de Jun. de 2023
Editada: Star Strider el 2 de Jun. de 2023
This appears to be a reasonably robust approach —
a = [1 23 56]*10^(-9);
b = a.*10.^ceil(-log10(abs(a))+1)
b = 1×3
10.0000 23.0000 56.0000
max_a = max(b)
max_a = 56.0000
a = [1 23 56]*10^(-6);
b = a.*10.^ceil(-log10(abs(a))+1)
b = 1×3
10 23 56
a = [1 23 56]*10^(10);
b = a.*10.^ceil(-log10(abs(a))+1)
b = 1×3
10 23 56
a = [1 23 56]*10^(-1);
b = a.*10.^ceil(-log10(abs(a))+1)
b = 1×3
10.0000 23.0000 56.0000
EDIT — Corrected typographical error
.

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