Error using vertcat Dimensions of arrays being concatenated are not consistent

3 views (last 30 days)
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; ...
Also, "Error using vertcat
Dimensions of arrays being concatenated are not consistent. " is written near line 419.
Thank you for support.
  1 Comment
Stephen23
Stephen23 on 20 May 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.

Sign in to comment.

Answers (1)

Infinite_king
Infinite_king on 20 May 2024
Edited: Infinite_king on 20 May 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))
7 3
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];
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
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.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!