필터 지우기
필터 지우기

Error using vertcat Dimensions of arrays being concatenated are not consistent

조회 수: 3 (최근 30일)
Tugce
Tugce 2024년 5월 20일
댓글: Stephen23 2024년 5월 20일
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
Stephen23
Stephen23 2024년 5월 20일
"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.

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

답변 (1개)

Infinite_king
Infinite_king 2024년 5월 20일
편집: Infinite_king 2024년 5월 20일
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.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by