How do I concatenate char and double classes?

I'm attempting to concatenate data of 2 different class types.
The first type is of Class char, with the size being 7 x 11.
z =
DUE
DUE
BT
PRE_REL
BT
BT
PRE_REL
The 2nd type is of Class double, with the size being 7 x 11.
y =
58570 -1245.0111 -4807.8222
58570 -1245.0111 -4807.8222
58572 -1400.0111 -4950.8222
58574 -1550.0111 -5000.8222
58576 -1600.0111 -5150.8222
58576 -1600.0111 -5150.8222
58578 -1750.0111 -5200.8222
The desired output would be a single array that looks like this:
DUE 58570 -1245.0111 -4807.8222
DUE 58570 -1245.0111 -4807.8222
BT 58572 -1400.0111 -4950.8222
PRE_REL 58574 -1550.0111 -5000.8222
BT 58576 -1600.0111 -5150.8222
BT 58576 -1600.0111 -5150.8222
PRE_REL 58578 -1750.0111 -5200.8222
In looking through the Programmer's Guide I'm not sure if I need to make a simple conversion or not. Any ideas would be helpful. Thanks.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 2일

1 개 추천

%Example
z =strvcat('DUE','DUE','BT','PRE_REL')
data=rand(4,3)
%convert your char array to cell array
c=cellstr(z)
%covert your double array to call array
n=num2cell(data)
out=[c n]

추가 답변 (1개)

Mischa Kim
Mischa Kim 2014년 5월 2일

1 개 추천

Brad, you could use a table. See this answer for reference.

댓글 수: 4

Brad
Brad 2014년 5월 2일
Mischa, I'm getting the following warning when i attempt to use the Table function:
Undefined function 'table' for input arguments of type 'double'.
Didn't think I'd need to convert the data types. Maybe I do.
per isakson
per isakson 2014년 5월 2일
편집: per isakson 2014년 5월 2일
What does
which table
return?
table is rather new in Matlab. It was introduced only a few releases ago. If you don't have table in your release you can use a cell array.
You poor guy. You must be using an old version of MATLAB. The wonderful new table data type only came into being with R2013b. Please upgrade because like Mischa said, the table is the best way to go. Otherwise you'll be stuck using a cell array. Definitely more complicated to use. See the FAQ on cell arrays: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F to give you an idea of when you need to use parentheses and when you need to use braces . Actually I see Azzi and Jose-Luis already gave you code for that so just use that if you can't upgrade.
Brad
Brad 2014년 5월 2일
Yep, I'm stuck with 2012B. Had to use the cell array.

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

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

질문:

2014년 5월 2일

댓글:

2014년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by