Error using vertcat Dimensions of arrays being concatenated are not consistent
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
Can anybody help me, cant understand why do i get this error when i run it?
I have an error that is Error using vertcat
Dimensions of arrays being concatenated are not consistent.
VariableLocations = ([COL; HPPC_Output.Properties.VariableNames; ...
the code is written below:
% 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
line 419 is VariableLocations = ([COL; HPPC_Output.Properties.VariableNames; ...
Dimensions of arrays being concatenated are not consistent. " is written near line 419.
Thank you for support.
1 commentaire
Stephen23
le 20 Mai 2024
"Can anybody help me, cant understand why do i get this error when i run it?"
Either COL and/or HPPC_Output.Properties.VariableNames do not have 37 columns.
Réponses (1)
Infinite_king
le 20 Mai 2024
Modifié(e) : Infinite_king
le 20 Mai 2024
Hi Tugce,
To concatenate A and B vertically, all dimensions except the first must be the same. For example, consider the following case,
A = zeros(2,3); % 2x3 matrix
B = zeros(5,3); % 5x3 matrix
% A and B can be concatenated vertically
C = [A;B];
disp(size(C))
B = zeros(5,4); % Now B is 5x4 matrix
% A and B cannot be concatenated vertically since the second dimension is
% not matching
C = [A;B];
The error has occurred while executing the following line. To resolve the error, print the dimensions of 'COL' and 'HPPC_Output.Properties.VariableNames' and verify whether they are matching or not.
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
Hope this is helpful.
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!