Borrar filtros
Borrar filtros

How to create this table/matrix?

3 visualizaciones (últimos 30 días)
Manny
Manny el 22 de Feb. de 2024
Comentada: Manny el 22 de Feb. de 2024
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:
CIV =
2448×3 table
SYMBOL TRADE_DATE Price
_______ __________ ____________________________
{'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
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
{'SPX'}
>> ForecastDates'
ans =
739302
739303
739304
739305
739308
739309
739310
739311
739312
739315
>>
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 comentarios
Manny
Manny el 22 de Feb. de 2024
@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
Stephen23 el 22 de Feb. de 2024
Editada: Stephen23 el 22 de Feb. de 2024
"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:

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Feb. de 2024
ForecastInfo = table(CIV.SYMBOL(1:10,:), ForecastDates', 'VariableNames', {'Symbol', 'Forcecast Dates'});

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by