How to initialize a table column to a character array?

조회 수: 6 (최근 30일)
Kurt
Kurt 2022년 11월 30일
댓글: Dyuman Joshi 2023년 10월 6일
I have a table "filetext" which is 19343x46. I want to append a colum on the right containing the character array 'MET'. In other words, 19343 rows of the characters 'MET'. How do I do this? I have tried various approaches.
I created a column that is the same height as filetext:
met = [height(filetext),1];
Then I tried populating it with 'MET'
met(1:height(filetext),1) = 'MET';
but I get the error message
"Unable to perform assignment because the size of the left side is 19393-by-1 and the size of the right side is 1-by-3."
If this was a simple zero initialization I could just do:
filler = zeros(height(filetext),1);
but I don't know how to do this for characters.
  댓글 수: 1
Kurt
Kurt 2022년 11월 30일
I could do all of this with a for loop, but I prefer not to.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 11월 30일
% a table:
filetext = table([1;2;3;4;5;6])
filetext = 6×1 table
Var1 ____ 1 2 3 4 5 6
% append a column of all 'MET' on the right:
filetext{:,end+1} = 'MET'
filetext = 6×2 table
Var1 Var2 ____ ____ 1 MET 2 MET 3 MET 4 MET 5 MET 6 MET
  댓글 수: 4
Bright
Bright 2023년 10월 6일
what if you try
filetext.var2 = MET
Dyuman Joshi
Dyuman Joshi 2023년 10월 6일
@Bright, why don't you try and see?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by