Adding a single left bracket and a single right bracket to a matrix

I want the following:
I get the following:
k = 13;
disp(['Number of neutral strand = ' num2str(k)])
Rb = 1.269/2/12; % ft
disp(['Radius of the circle passing through the centers of the neutral strands, Rb = ' num2str(Rb) ' ft'])
RDc = 0.498/2/12; % ft
disp(['Phase conductor equivalent (self) radius, RDc = ' num2str(RDc) ' ft'])
RDs = 0.1019/2/12; % ft
disp(['Neutral strand equivalent radius, RDs = ' num2str(RDs) ' ft'])
yag = (77.3619i)/(log(Rb/RDc)-(1/k)*(log(k*(RDs/Rb)))); %μS/mile
disp(['Shunt admittance, yag = ' num2str(yag) ' μS/mile'])
Yabc = diag([yag,yag,yag]);
disp(Yabc)
temp = splitlines(formattedDisplayText(Yabc));
temp(2) = temp(2) + " μS/mile";
disp(char(temp))

 Réponse acceptée

I'm not sure if this can be done in the command window, but in a Live Script matrix output can be shown with square brackets.
A = rand(3);
sympref('FloatingPointOutput',true);
sympref('MatrixWithSquareBrackets',true);
ans = logical
0
disp(sym(A))

4 commentaires

I am using Matlab live editor. The brackets look great. How do I add my units back?
k = 13;
disp(['Number of neutral strand = ' num2str(k)])
Rb = 1.269/2/12; % ft
disp(['Radius of the circle passing through the centers of the neutral strands, Rb = ' num2str(Rb) ' ft'])
RDc = 0.498/2/12; % ft
disp(['Phase conductor equivalent (self) radius, RDc = ' num2str(RDc) ' ft'])
RDs = 0.1019/2/12; % ft
disp(['Neutral strand equivalent radius, RDs = ' num2str(RDs) ' ft'])
yag = (77.3619i)/(log(Rb/RDc)-(1/k)*(log(k*(RDs/Rb)))); %μS/mile
disp(['Shunt admittance, yag = ' num2str(yag) ' μS/mile'])
Yabc = diag([yag,yag,yag]);
sympref('FloatingPointOutput',true);
sympref('MatrixWithSquareBrackets',true);
disp(sym(Yabc))
Is 'mi' acceptable over 'mile'? I guess the units are displayed in blue font. Maybe there's a preference for that?
A = rand(3);
d1 = digits(5); % set the precision for the display
sympref('MatrixWithSquareBrackets',true);
u = symunit;
mcspm = u.microsecond/u.mile;
B = vpa(A);
displayFormula('B*mcspm')
Or
displayFormula(["B","'μS/mile'"])
digits(d1); % reset to whatever the digits were
That worked great! Thanks.
That's a really effective use of displayFormula !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by