How to pull value of table for char array?

조회 수: 150 (최근 30일)
Budding MATLAB Jockey
Budding MATLAB Jockey 2020년 5월 21일
댓글: Budding MATLAB Jockey 2020년 5월 21일
Hi there, I am new to tables (using 2019a) and I can't figure this bit out.
I have char arrays in a table:
t(1,'Domain')
ans =
table
Domain
_____________________
{'www.wisebread.com'}
And I want to make a char array using a value from that table to input as a url in a webwrite();
When I use the code
a = 'www.checkthing.com\thingcheck?domain='+t(1,'Domain')+'&secretkey=secretcode'
I get the error
Undefined operator '+' for input arguments of type 'table'.
alternatively if I use strcat I get the error
Inputs must be character vectors, cell arrays of character vectors, or string arrays.
I think this is supposed to be simple but I can't figure out how to use table values in normal operations :(

채택된 답변

Stephen23
Stephen23 2020년 5월 21일
편집: Stephen23 2020년 5월 21일
"When I use the code"
t(1,'Domain')
then your indexing returns a table, because parentheses is used to return a table (i.e. usually a sub-table of the table you are indexing into). This is clearly explained in the documentation:
Just like other container classes (e.g. cell array, string array), if you want to access the content of a table you need to use curly braces (not parentheses):
t{1,'Domain'}
"I think this is supposed to be simple..."
It is simple. For container classes table, cell arrays, and string arrays:
  • () refers to the container array itself.
  • {} refers to the contents of the array.
If you want part of the cell array, use parentheses. If you want whatever is in the cell array, use curly braces.

추가 답변 (1개)

Mehmed Saad
Mehmed Saad 2020년 5월 21일
편집: Mehmed Saad 2020년 5월 21일
Because t(1,'Domain') is of type table. You need to convert that table output to string or cell. To do that type on Command window
t.Domain(1)
ans =
1×1 cell array
{'www.wisebread.com'}
So basically we extracted the data from table
Now do that strcat step
a = strcat('www.checkthing.com\thingcheck?domain=',t.Domain(1),'&secretkey=secretcode')
  댓글 수: 1
Budding MATLAB Jockey
Budding MATLAB Jockey 2020년 5월 21일
oh nice, multiple ways to access the content! many thanks!

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

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by