Borrar filtros
Borrar filtros

unmatched the number of variables specified

3 visualizaciones (últimos 30 días)
Tugce
Tugce el 7 de Mzo. de 2024
Comentada: Tugce el 21 de Mayo de 2024
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 comentarios
Mathieu NOE
Mathieu NOE el 7 de Mzo. de 2024
please share a working code + some files if you can
Tugce
Tugce el 21 de Mayo de 2024
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);

Iniciar sesión para comentar.

Respuestas (2)

Florian Bidaud
Florian Bidaud el 7 de Mzo. de 2024
Editada: Florian Bidaud el 7 de Mzo. de 2024
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 el 14 de Mzo. de 2024
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.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by