How to take the product of distinct array values?

1 visualización (últimos 30 días)
Sean
Sean el 25 de Jun. de 2014
Comentada: Sean el 25 de Jun. de 2014
clc;
clear all;
close all;
Bx = 720;
By = 360;
g = gcd(Bx,By);
f = factor(g);
f_prod = prod(f);
In this example f = [ 2 2 2 3 3 5 ], and prod(f) = 360, but I just want to receive the product of distinct primes (i.e. 2*3*5). Is there a way to do this?

Respuesta aceptada

John D'Errico
John D'Errico el 25 de Jun. de 2014
prod(unique(f))

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by