Generating a table with text
조회 수: 62 (최근 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!