How to insert a cell with string into a table as variable

조회 수: 14 (최근 30일)
Sandeep Nair
Sandeep Nair 2021년 4월 22일
댓글: Walter Roberson 2021년 4월 23일
I have a cell B of 1x59 strings in it and i want to insert it into a table T as variable names
When am using the command
T.VariableNames.Properties = B; am getting the following error
"The VariableNames property is a cell array of character vectors. To assign multiple variable names, specify names in a
string array or a cell array of character vectors."
I checked multiple times by checking whether the cell is str from command iscellstr and it returns me 1.
Can anyone please help how to solve this problem
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 4월 22일
You cannot use a cell array of strings. You need to use a cell array of character vectors, or you need to use a non-scalar string() array.

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

채택된 답변

Stephan
Stephan 2021년 4월 22일
편집: Stephan 2021년 4월 22일
The solution is inside the error message:
  1. B is a cell array of strings
  2. specify names in a string array or
  3. cell array of character vectors
What you have is 1. and what you need is either 2. or 3.
A = {"Name1", "Name2", "Name3"}
A = 1×3 cell array
{["Name1"]} {["Name2"]} {["Name3"]}
A_new = [A{:}]
A_new = 1×3 string array
"Name1" "Name2" "Name3"
  댓글 수: 7
Sandeep Nair
Sandeep Nair 2021년 4월 23일
Thanks for the answers,i was able to find the solution i checked my cells with isvarname and some of the cells were having dots in between which i removed and now its working fine ,thanks
Walter Roberson
Walter Roberson 2021년 4월 23일
Variable names with dots in them are permitted, R2019b and later (if I remember correctly.) You did not happen to indicate which release you are using.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by