How to create this table/matrix?

조회 수: 2 (최근 30일)
Manny 2024년 2월 22일
댓글: Manny 2024년 2월 22일
Hi everyone
I need to create a matrix that is the concatenation of two different sources.
First column of concatenated matrix - First 10 entries of column SYMBOL of table CIV:
2448×3 table
_______ __________ ____________________________
{'SPX'} 7.393e+05 11.654
{'SPX'} 7.393e+05 11.337
{'SPX'} 7.393e+05 10.736
Second column of concatenated matrix - All entries of ForecastDates:
T0 = datetime(2024,02,16);
T1 = datetime(busdate(T0,1));
T2 = datetime(busdate(T1,1));
T3 = datetime(busdate(T2,1));
T4 = datetime(busdate(T3,1));
T5 = datetime(busdate(T4,1));
T6 = datetime(busdate(T5,1));
T7 = datetime(busdate(T6,1));
T8 = datetime(busdate(T7,1));
T9 = datetime(busdate(T8,1));
T10 = datetime(busdate(T9,1));
ForecastDates = [T1 T2 T3 T4 T5 T6 T7 T8 T9 T10];
I need a 10 by 2 matrix. The first column is SYMBOL and second is ForecastDates'. I did the following but I am getting an error:
>> ForecastInfo = [CIV.SYMBOL(1:10,:) ForecastDates']
Error using horzcat
Inconsistent concatenation dimensions because a 10-by-1 'double' array was converted to a 1-by-1 'cell'
array. Consider creating arrays of the same type before concatenating.
>> CIV.SYMBOL(1:10,:)
ans =
10×1 cell array
>> ForecastDates'
ans =
Each is a 10 by 1 so it looks ok but I am not sure what I did wrong. Is someone able to help me with this?
Thank you
  댓글 수: 3
Manny 2024년 2월 22일
@Stephen23, what do you mean by class?
I need columns 1 and 2 to be different data types b/c that is how the original CIV matrix is setup. How do I do this?
Stephen23 2024년 2월 22일
편집: Stephen23 2024년 2월 22일
"what do you mean by class?"
Class is basically a fancy word for the type of an array (the terms type and class are often treated as synonyms).
MATLAB has several numeric class arrays, e.g. DOUBLE, SINGLE, UINT8, etc. Numeric arrays contain numbers.
MATLAB also has container classes (which are arrays that can contain other arrays), for example CELL, STRUCT, TABLE, etc.
An array itself is just the instance of one class.
"I need columns 1 and 2 to be different data types b/c that is how the original CIV matrix is setup. How do I do this?"
Use a TABLE:

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

채택된 답변

Walter Roberson
Walter Roberson 2024년 2월 22일
ForecastInfo = table(CIV.SYMBOL(1:10,:), ForecastDates', 'VariableNames', {'Symbol', 'Forcecast Dates'});
  댓글 수: 1
Manny 2024년 2월 22일
thank you so much! it works

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

추가 답변 (0개)


Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by