필터 지우기
필터 지우기

unmatched the number of variables specified

조회 수: 3 (최근 30일)
Tugce
Tugce 2024년 3월 7일
댓글: Tugce 2024년 5월 21일
Hello,
I have different test data, then I try to get plots. However, some of test data gives their plot, some of them doesn't work. For example, cycle test data to obtain the plot works whereas HPPC test doesn't work.
I have the error written below.
Error using tabular/renamevars
The number of new variable names must match the number of variables specified.
Empties = renamevars(Empties, Empties.Properties.VariableNames, ["Storage_Temperature", "Storage_Time_Months", "Notes", "Validate"]); ...
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2024년 3월 7일
please share a working code + some files if you can
Tugce
Tugce 2024년 5월 21일
Hi,
Here is my code. The error is in the line that is "Empties = renamevars(Empties, Empties.Properties.VariableNames, ["Storage_Temperature", "Storage_Time_Months", "Notes", "Validate"]); ...
% Add empty variables - this will need updating for the option to input storage temp, time and add notes
Empties = num2cell(NaN(height(HPPC_Output), length(COL) - width(HPPC_Output))); % Create empty array for empty variables required on output
Empties = cell2table(Empties); % Convert to table
Empties = renamevars(Empties, Empties.Properties.VariableNames, ["Storage_Temperature", "Storage_Time_Months", "Notes", "Validate"]); ...
% Add required variables
HPPC_Output = [HPPC_Output Empties]; % Add to output table
% Re-arrange variable locations
VariableLocations = ([COL; HPPC_Output.Properties.VariableNames; ...
num2cell([3:14 22 36 28 33 16:19 24 23 25 20 21 15 1 30 29 27 32 26 31 34 35 37 2])])'; % Manually input location of variables wrt COL - future work includes automating this
VariableLocations = cell2table(VariableLocations); % Convert to table
VariableLocations = sortrows(VariableLocations, 3, "Ascend"); % Sort so numbers are ascending
for i = 1:height(VariableLocations)
HPPC_Output = movevars(HPPC_Output, VariableLocations{i,2}, 'After', width(HPPC_Output)); % Move each variable to the...
% end of the table until they are in order
end
% Finalise UIC
for i = 1:height(HPPC_Output)
j = num2str(i); % Convert row number, i, to a string
HPPC_Output.UIC(i,:) = append(HPPC_Output.UIC(i,:), j); % Append string to the end of UIC
end
% Renaming the table variables to match COL
VariableNames = HPPC_Output.Properties.VariableNames;
HPPC_Output = renamevars(HPPC_Output, VariableNames, COL);

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

답변 (2개)

Florian Bidaud
Florian Bidaud 2024년 3월 7일
편집: Florian Bidaud 2024년 3월 7일
The error is self explanatory, Empties.Properties.VariableNames returns a cell array of all the variable names. You try to replace them by ["Storage_Temperature", "Storage_Time_Months", "Notes", "Validate"]. so 4 variables. It means the table 'Empties' does not have 4 variables.
I suspect in your case one of the variables was empty and then got removed from the table.

Tugce
Tugce 2024년 3월 14일
Hi,
Thank you for your comments.
I solved the error while deleting 2 variables. Because there are 2 coloumbs in the empties file. If I delete any 2 variable, it works.
For example, if I write like that " Empties = renamevars(Empties, Empties.Properties.VariableNames, ["Storage_Temperature", "Storage_Time_Months"]); ... " with just 2 varilable, then I obtained the table in the picture "Variables_Empties_2 coulomb". However, there is still no result because of another error. Before solving another error, I would like to add 2 more coulomb for "Notes" and "Validate" since I need its value. But I cannot add 2 more coulomb in empties file. How can I add?
Also, you can find the code's screenshot attached.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by