in matrix, convert fraction part into decimal

조회 수: 78 (최근 30일)
Naseeb Gill
Naseeb Gill 2016년 12월 16일
댓글: Naseeb Gill 2016년 12월 16일
Hello, I have a matrix in which each element is comes out as fraction part but I want it as decimal part. I'm using symbolic expression in my code with matlabFunction. Code is given below.
syms a b c d e f;
x = [a+b b+c;d+e e+f];
y = matlabFunction(x)
a = 0.222;
b = 3.57;
c = 1.5;
d = 0.351;
e = -.22;
f = f;
y(a,b,c,d,e,f);
The output of this function is like below:
>> y(a,b,c,d,e,f)
ans =
[ 474/125, 507/100]
[ 131/1000, f - 11/50]
I tried to use double and vpa but I'm not getting any results. Can somebody tell me how to solve this problem.
Thanks.

채택된 답변

KSSV
KSSV 2016년 12월 16일
vpa(y(a,b,c,d,e,f))
ans =
[ 3.792, 5.07]
[ 0.131, f - 0.22]
  댓글 수: 1
Naseeb Gill
Naseeb Gill 2016년 12월 16일
Thanks @KSSV, it works perfectly. Actually I was using vpa like
x1 = [a+b b+c;d+e e+f];
x = vpa(x1);
so result was not coming out in decimal form with this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by