function r = r_mul(a,b)
a = [a(1),a(2)];
b = [b(1),b(2)];
M = a(2)*b(2); %finding common denominator
N = times(a,b); %multiplying the two fractions
C = gcd(N,M); %cancelling common factor
X = N./C; %simplifying fraction
Y = M./C; %simplifying fraction
r = [X,Y]; %final answer
end
I have this script file here. Adding the values of a(1),a(2),b(1),b(2) in the command window then running the function gives me a four-component vector with two 1's but I only need the other values how do I get rid of the 1's??:
a(1)=5040, a(2)=17
b(1)=22, b(2)=342920
>> r_mul(a,b)
ans =
2772 1 145741 1

 채택된 답변

Stephan
Stephan 2019년 3월 26일

0 개 추천

a(1)=5040;
a(2)=17;
b(1)=22;
b(2)=342920;
res = r_mul(a,b)
function r = r_mul(a,b)
M = a(2)*b(2); %finding common denominator
N = times(a,b); %multiplying the two fractions
C = gcd(N,M); %cancelling common factor
X = N./C; %simplifying fraction
Y = M./C; %simplifying fraction
r = [X(1),Y(1)]; %final answer
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 3월 26일

댓글:

2019년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by