Variable names in array2table when creating table, "duplicate variable names" error

8 次查看(过去 30 天)
Hello, I have been haveing trouble while assigning variable names in this section of code:
master = padcat(peakcnt_eng,startTime,engTime(timePeak_eng),spkPeak_eng,peakDiff_time,peakDiff_val,emptyCOL,mass_first10,mass_first20,mass_first30,mass_first50,mass_first100,coldStart_sumM,trans_sumM,hotStart_sumM,peakcnt_mass,traceTime(spkStrt_m),timePeak_m,traceTime(spkEnd_m),spkArea_m,spkfront_m,emptyCOL,cnt_first10,cnt_first20,cnt_first30,cnt_first50,cnt_first100,coldStart_sumCnt,trans_sumCnt,hotStart_sumCnt,peakcnt_count,traceTime(spkStrt_cnt),timePeak_cnt,traceTime(spkEnd_cnt),spkArea_cnt,spkfront_cnt);
parameters = {'EngineStartNumber','TimeofEngineStart_sec','TimeofEngineAccelerationPeak_sec','EngineAccelrationAtPeak_RPMperSec','CrankAndEngStartTimeDiff_s','CrankAndEngStartValueDiff_RMPperSec','skip','Mass_first10sec_mg','Mass_first20sec_mg','Mass_first30sec_mg','Mass_first50sec_mg','Mass_first100sec_mg','ColdStart_sumM','Transient_sumM','HotStart_sumM','SootPeakNumber','TimeofSootSpikeStart_sec','TimeofSootSpikePeak_sec','TimeofSootSpikeEnd_sec','MassofSpikeWHOLE_mg','MassofSpikeSTART2PEAK_mg','skip1','Cnt_first10sec_mg','Cnt_first20sec_mg','Cnt_first30sec_mg','Cnt_first50sec_mg','Cnt_first100sec_mg','ColdStart_sumCnt','Transient_sumCnt','hotStart_sumCnt','SootCountPeakNumber','TimeofSootCountSpikeStart_sec','TimeofSootCountSpikePeak_sec','TimeofSootSpikeEnd_sec','PRTNUMofSpikeWHOLE_mg','PRTNUMofSpikeSTART2PEAK_mg'};
masterTable = array2table(master,'VariableNames',parameters);
I am very confused by this resulting error:
Error using matlab.internal.tabular.private.varNamesDim/validateAndAssignLabels (line 321)
Duplicate variable name: 'Transient_sumCnt'.
Error in matlab.internal.tabular.private.tabularDimension/setLabels (line 173)
obj = obj.validateAndAssignLabels(newLabels,indices,fullAssignment,fixDups,fixEmpties,fixIllegal);
Error in matlab.internal.tabular.private.tabularDimension/createLike_impl (line 355)
obj = obj.setLabels(dimLabels,[]);
Error in matlab.internal.tabular.private.varNamesDim/createLike (line 70)
obj = obj.createLike_impl(dimLength,dimLabels);
Error in tabular/initInternals (line 207)
t.varDim = t.varDim.createLike(nvars,varnames); % error if invalid, duplicate, or empty
Error in table.init (line 327)
t = initInternals(t, vars, numRows, rowLabels, numVars, varnames);
Error in array2table (line 64)
t = table.init(vars,nrows,rownames,nvars,varnames);
Error in MAT_Load_Data_NewerFormats (line 263)
masterTable = array2table(master,'VariableNames',parameters);
The actual variable name 'Transient_sumCnt' does not seem to matter at all as I can change it to any other name and the same message results.
Any information on the cause of this error or else where I should go to look would be greatly appreciated. Thank you!

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2020-7-24
No way to know what is in "master". But there is a duplicated name in 'parameters'. The name 'TimeofSootSpikeEnd_sec' appeared twice. Not sure why the error message says 'Transient_sumCnt'

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by