Generating a table with text

62 vues (au cours des 30 derniers jours)
Jorge Rodriguez
Jorge Rodriguez le 23 Août 2017
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

Réponse acceptée

Jan
Jan le 24 Août 2017
Modifié(e) : Jan le 24 Août 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!

Plus de réponses (1)

Walter Roberson
Walter Roberson le 24 Août 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 commentaire
Ernest Modise - Kgamane
Ernest Modise - Kgamane le 24 Mar 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'

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by