Generating a table with text
59 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jorge Rodriguez
el 23 de Ag. de 2017
Comentada: Ernest Modise - Kgamane
el 24 de Mzo. de 2021
Hello Community,
I have a question about the command to generate a table with several variables. I have 5 arrays and one is a text array.
I want to join the 5 arrays into 1 table. However, for some reason the text array place ' ' symbols on each text. In other words, A(a b c ...,1) B(1 2 3 ...,1) C(1 2 3 ...,1) etc. the results ABCDE_Table=table(A,B,C,D,E) but by opening the ABCDE_Table I realize that column A has been modified by ABCDE_Table(:,1)=('a' 'b' 'c' ....,1).
How do I remove ' ' or import the text with out ' '?
Thanks for your time
0 comentarios
Respuesta aceptada
Jan
el 24 de Ag. de 2017
Editada: Jan
el 24 de Ag. de 2017
I'm not sure what "A(a b c ...,1)" means. Better post some working code, which reproduces the problem. But I think, that there is no problem at all: If a table contains strings, they are displayed in the command window with surrounding quotes to distinguish the string '1' from the number 1. But this appears in the command window only, it does not concern the stored values.
A = {'a'; 'b'}
B = {1; 2}
T = table(A, B);
disp(T)
A B
___ ___
'a' [1]
'b' [2]
But:
T.A{1}
a % No quotes!
0 comentarios
Más respuestas (1)
Walter Roberson
el 24 de Ag. de 2017
You cannot change that. It is the way that the display function is defined for tables. MATLAB often displays '' around text. For example,
>> test.dat = 'aaa'
test =
struct with fields:
dat: 'aaa'
You have to understand that table objects are not designed for output layout: they are designed for manipulating tabular data of mixed data types. There is almost no format control for them.
If you need to output in text form without the '' marks, then you need to write your own output routines, perhaps converting the table contents into a cell array and then using a careful fprintf() format.
1 comentario
Ernest Modise - Kgamane
el 24 de Mzo. de 2021
Thank for your answer to the original question,
I wanted to use the same approach to create a table like
0 00
1 01
2 11
3 101
4 1001
5 10001
6 100001
where 0 - 6 are the table index in numerics, and 00 to 100001 are some binary code I want to be a string.
Now using your code below if I print T.A{1}
My results come with quotes,
For my application I want for example to output a concatenated string say for index 3 and index 1 in that order,
i.e. 10101
for the example above, the code below will output '101''01'
Please help on how I can resolve this.
> A = {'a','b'}';
>> B = {1,3}';
>> T = table(A,B);
>> disp(T)
A B
_____ _____
{'a'} {[1]}
{'b'} {[3]}
>> T.A{1}
ans =
'a'
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!