Generating a table with text
65 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2017-8-24
编辑:Jan
2017-8-24
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 个评论
更多回答(1 个)
Walter Roberson
2017-8-24
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 个评论
Ernest Modise - Kgamane
2021-3-24
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'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!