add element in table

5 Ansichten (letzte 30 Tage)
Trop Trader
Trop Trader am 1 Mär. 2024
Beantwortet: Fangjun Jiang am 1 Mär. 2024
ff(:,1)
ans =
table
Name
____
TEST
%%*****************************************
d1(:,1)
ans =
table
Name
________
"TEST_1"
ff(end+1,:)=d1
Error using ()
Unable to perform assignment for table variable 'Name' because its size on the left side is 1-by-4 and the size
of the corresponding variable on the right side is 1-by-1.
i don't understand this error...size name in ff and d1 is the same
K>> size(ff(:,1))
ans =
1 1
K>> size(d1(:,1))
ans =
1 1

Akzeptierte Antwort

Voss
Voss am 1 Mär. 2024
% load stuff from the mat files:
d1 = load('matlab_d1.mat','d1').d1;
ff = load('matlab_ff.mat','ff').ff;
d1
d1 = 1x42 table
Name Dwmy LS_abilitaLong LS_abilitaShort LS_long LS_short LS_th LS_minTrades LS_avgEquity Avg_abilitaFilter Avg_mode Avg_period Avg_th Avg_minTrades Dev_enable Dev_enableTestDN Dev_enableTestUP Dev_devNumDn Dev_devNumUp Dev_periods Peak_enable Peak_period Peak_minTrades Rank_enable Rank_period Rank_mode Rank_type Rank_minTrades Rank_maxCat Rank_using_type Rank_using_timeframe Rank_normalize_by_cashvola Backtest Cormode CorTH BackAdvanc_tradeLMT BackAdvanc_shiftC BackAdvanc_cloops Degrade_enable Degrade_initialDeg Degrade_degressMode MaxPercPortfolio_Disable ________ ____ ______________ _______________ _______ ________ _____ ____________ ____________ _________________ ________ __________ ______ _____________ __________ ________________ ________________ ____________ ____________ ___________ ___________ ___________ ______________ ___________ ___________ _________ _________ ______________ ___________ _______________ ____________________ __________________________ ________ _______ _____ ___________________ _________________ _________________ ______________ __________________ ___________________ ________________________ "TEST_1" 31 false false 9 2 0 16 0 0 1 4 40 16 0 1 0 1 1 150 0 0 12 0 6 1 1 16 3 1 1 0 1 1 0.75 0.375 0.75 2 0 100 0 0
ff
ff = 1x42 table
Name Dwmy LS_abilitaLong LS_abilitaShort LS_long LS_short LS_th LS_minTrades LS_avgEquity Avg_abilitaFilter Avg_mode Avg_period Avg_th Avg_minTrades Dev_enable Dev_enableTestDN Dev_enableTestUP Dev_devNumDn Dev_devNumUp Dev_periods Peak_enable Peak_period Peak_minTrades Rank_enable Rank_period Rank_mode Rank_type Rank_minTrades Rank_maxCat Rank_using_type Rank_using_timeframe Rank_normalize_by_cashvola Backtest Cormode CorTH BackAdvanc_tradeLMT BackAdvanc_shiftC BackAdvanc_cloops Degrade_enable Degrade_initialDeg Degrade_degressMode MaxPercPortfolio_Disable ____ ____ ______________ _______________ _______ ________ _____ ____________ ____________ _________________ ________ __________ ______ _____________ __________ ________________ ________________ ____________ ____________ ___________ ___________ ___________ ______________ ___________ ___________ _________ _________ ______________ ___________ _______________ ____________________ __________________________ ________ _______ _____ ___________________ _________________ _________________ ______________ __________________ ___________________ ________________________ TEST 31 false false 9 2 0 16 0 0 1 4 40 16 0 1 0 1 1 150 0 0 12 0 6 1 1 16 3 1 1 0 1 1 0.75 0.375 0.75 2 0 100 0 0
Name in table d1 is a string array:
class(d1.Name)
ans = 'string'
But Name in table ff is a character array:
class(ff.Name)
ans = 'char'
To combine them they've got to be the same type, so you've got to convert one or both to something else. Easiest is probably making ff.Name into a string:
ff.Name = string(ff.Name)
ff = 1x42 table
Name Dwmy LS_abilitaLong LS_abilitaShort LS_long LS_short LS_th LS_minTrades LS_avgEquity Avg_abilitaFilter Avg_mode Avg_period Avg_th Avg_minTrades Dev_enable Dev_enableTestDN Dev_enableTestUP Dev_devNumDn Dev_devNumUp Dev_periods Peak_enable Peak_period Peak_minTrades Rank_enable Rank_period Rank_mode Rank_type Rank_minTrades Rank_maxCat Rank_using_type Rank_using_timeframe Rank_normalize_by_cashvola Backtest Cormode CorTH BackAdvanc_tradeLMT BackAdvanc_shiftC BackAdvanc_cloops Degrade_enable Degrade_initialDeg Degrade_degressMode MaxPercPortfolio_Disable ______ ____ ______________ _______________ _______ ________ _____ ____________ ____________ _________________ ________ __________ ______ _____________ __________ ________________ ________________ ____________ ____________ ___________ ___________ ___________ ______________ ___________ ___________ _________ _________ ______________ ___________ _______________ ____________________ __________________________ ________ _______ _____ ___________________ _________________ _________________ ______________ __________________ ___________________ ________________________ "TEST" 31 false false 9 2 0 16 0 0 1 4 40 16 0 1 0 1 1 150 0 0 12 0 6 1 1 16 3 1 1 0 1 1 0.75 0.375 0.75 2 0 100 0 0
Then the operation works:
ff(end+1,:) = d1
ff = 2x42 table
Name Dwmy LS_abilitaLong LS_abilitaShort LS_long LS_short LS_th LS_minTrades LS_avgEquity Avg_abilitaFilter Avg_mode Avg_period Avg_th Avg_minTrades Dev_enable Dev_enableTestDN Dev_enableTestUP Dev_devNumDn Dev_devNumUp Dev_periods Peak_enable Peak_period Peak_minTrades Rank_enable Rank_period Rank_mode Rank_type Rank_minTrades Rank_maxCat Rank_using_type Rank_using_timeframe Rank_normalize_by_cashvola Backtest Cormode CorTH BackAdvanc_tradeLMT BackAdvanc_shiftC BackAdvanc_cloops Degrade_enable Degrade_initialDeg Degrade_degressMode MaxPercPortfolio_Disable ________ ____ ______________ _______________ _______ ________ _____ ____________ ____________ _________________ ________ __________ ______ _____________ __________ ________________ ________________ ____________ ____________ ___________ ___________ ___________ ______________ ___________ ___________ _________ _________ ______________ ___________ _______________ ____________________ __________________________ ________ _______ _____ ___________________ _________________ _________________ ______________ __________________ ___________________ ________________________ "TEST" 31 false false 9 2 0 16 0 0 1 4 40 16 0 1 0 1 1 150 0 0 12 0 6 1 1 16 3 1 1 0 1 1 0.75 0.375 0.75 2 0 100 0 0 "TEST_1" 31 false false 9 2 0 16 0 0 1 4 40 16 0 1 0 1 1 150 0 0 12 0 6 1 1 16 3 1 1 0 1 1 0.75 0.375 0.75 2 0 100 0 0

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 1 Mär. 2024
You should check size(ff(end,:)). I assume it has 4 columns.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by