How to take the product of distinct array values?

1 回表示 (過去 30 日間)
Sean
Sean 2014 年 6 月 25 日
コメント済み: Sean 2014 年 6 月 25 日
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?

採用された回答

John D'Errico
John D'Errico 2014 年 6 月 25 日
prod(unique(f))
  1 件のコメント
Sean
Sean 2014 年 6 月 25 日
Cheers mate.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by