What instruction could give me this result?

조회 수: 1 (최근 30일)
AverageMatlaber
AverageMatlaber 2021년 5월 10일
답변: Walter Roberson 2021년 5월 10일
If I have the following matrix in MATLAB;
syms a;
A=[a, a+1/2 ; a+1/3, a+1/4]
And I want to obtain the next result using one instruction;
[ a (2*a+1)/2 ]
[ (3*a+1)/3 (4*a+1)/4 ]
What instruction could perform this? Thanks in advance!
  댓글 수: 2
Matt J
Matt J 2021년 5월 10일
You don't need any instructions. The "result" is already equal to A.
AverageMatlaber
AverageMatlaber 2021년 5월 10일
Yes but, there is some way that MATLAB displays on screen the solution in that specific way? Including the parentheses and the divisions?

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 10일
You cannot get MATLAB to display in that particular way as a symbolic expression. You can convert to character and display.
syms a;
A=[a, a+1/2 ; a+1/3, a+1/4]
A = 
[n, d] = numden(A)
n = 
d = 
categorical(arrayfun(@(n,d) "(" + n + ")/" + d, string(n), string(d)))
ans = 2×2 categorical array
(a)/1 (2*a + 1)/2 (3*a + 1)/3 (4*a + 1)/4
You would need more work to eliminate the () for the cases where there is nothing being added.

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by