필터 지우기
필터 지우기

How to take the product of distinct array values?

조회 수: 2 (최근 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))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by