Removing quotations from table display

10 views (last 30 days)
Connor LeClaire
Connor LeClaire on 21 Oct 2021
Edited: dpb on 21 Oct 2021
Trying to display a symbolic matrix in a table, however directly displaying using table or array2table causes the symbolic matrix to be displayed as:
After casting the symbolic matrix as a string, double quotes surround each input:
clear all;
clc;
numVars = input('How many joints would you like to enter: ');
DH = sym(zeros(numVars,4));
DHparameters = ["a"; "alpha"; "d"; "theta"];
i = string(1:numVars);
for j=1:numVars
clc;
disp("JOINT "+num2str(j)+" of "+num2str(numVars));
pR = input('Is this joint prismatic or revolute (p/r): ','s');
DH(j,1) = sym(input("Enter DH parameter a for joint " + num2str(j)+": "));
DH(j,2) = sym(input('Enter DH parameter alpha: '));
if pR=='p'
DH(j,4) = sym(input('Enter DH parameter theta: '));
DH(j,3) = sym("d_"+num2str(j),'real');
else
DH(j,3) = sym(input('Enter DH parameter d: '));
DH(j,4) = sym("theta_"+num2str(j),'real');
end
end
clc;
table1 = array2table(DH, 'RowNames',i,'VariableNames',{'a', 'alpha', 'd', 'theta'});
%table1 = table(i,string(DH),'VariableNames',{'i', 'a alpha d theta'});
disp(table1);
If there is a different way to display this to the user I am open to that as well!
  3 Comments
dpb
dpb on 21 Oct 2021
As Scott shows below, it can be done, but turns into a fair amount of work pretty quickly.

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 21 Oct 2021
Edited: Scott MacKenzie on 21 Oct 2021
Seems like you just want a more visually appealing presentation for the user. Something like this might work:
vNames = {'a' 'alpha' 'd', 'theta'};
T = array2table(["0" "0" "1/2" "theta_1"; "0" "0" "d_2" "pi/2"], 'VariableNames', vNames);
C = [num2cell(1:height(T))' table2cell(T)]';
s = newline;
s = [s sprintf('==================================\n')];
s = [s sprintf('row %4s%8s%8s%10s\n', vNames{:})];
s = [s sprintf('----------------------------------\n')];
s = [s sprintf('%3d %4s%8s%8s%10s\n', C{:})];
s = [s sprintf('==================================\n')];
disp(s);
================================== row a alpha d theta ---------------------------------- 1 0 0 1/2 theta_1 2 0 0 d_2 pi/2 ==================================
  4 Comments
Connor LeClaire
Connor LeClaire on 21 Oct 2021
Ah ok, good to know. It's more a sanity check for the user to make sure their values are correct for what they expect.
Thanks for all your help!

Sign in to comment.

More Answers (1)

dpb
dpb on 21 Oct 2021
Edited: dpb on 21 Oct 2021
It's more a sanity check for the user to make sure their values are correct for what they expect.
And there's where the purpose of and value of the "" come in to play -- you are able to see if, for example, there are superfluous blanks in the data field this way that would be completely hidden otherwise, but perhaps cause a failure of a text search in string-matching code.
While I agree it is sometimes a little off-putting, the basics of the command window are well served by the choices TMW has made.
Two things I have done on occasion when I did want to make the presentation "cleaner" --
  1. Use cellstr() instead of string() -- the single quotes aren't quite as heavy and if there's nothing being done that is really dependent upon the string class in the application, but just looking as here, unlikely to lose anyfunctionality.
  2. Convert to categorical -- that way, since it is a not a type of string variable, MATLAB doesn't add any quotes:
vNames = {'a' 'alpha' 'd', 'theta'};
T=array2table(["0" "0" "1/2" "theta_1"; "0" "0" "d_2" "pi/2"], 'VariableNames', vNames);
T.a=categorical(T.a);
T.alpha=categorical(T.alpha);
T.d=categorical(T.d);
T.theta=categorical(T.theta);
Then you can write
>> disp(T)
a alpha d theta
_ _____ ___ _______
0 0 1/2 theta_1
0 0 d_2 pi/2
>>
Of course, you can wrap the conversion of the symbolic to string inside the call to categorical when creating the table; I don't have the TB so started with Connor's string version...

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!