Removing quotations from table display
Mostrar comentarios más antiguos
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 comentarios
dpb
el 21 de Oct. de 2021
The double quotes are a fignewton of the MATLAB display logic to indicate the type of the variable -- strings are double-quoted, cell-strings are single-quoted so you can visibly tell them apart. The quotes of either style are NOT part of the data and cannot be removed in the default output in the command window.
They don't hurt anything, do they, why not just leave as is?
If you export the table to some other format, only the data will be retained unless you choose something like quoted strings in a CSV file (always a good choice if using CSV, of course).
Connor LeClaire
el 21 de Oct. de 2021
dpb
el 21 de Oct. de 2021
As Scott shows below, it can be done, but turns into a fair amount of work pretty quickly.
Respuesta aceptada
Más respuestas (1)
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" --
- 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.
- 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...
Categorías
Más información sobre Text Data Preparation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!