Dimensions of arrays being concatenated are not consistent

조회 수: 7 (최근 30일)
Awais Khan
Awais Khan 2020년 2월 12일
댓글: Walter Roberson 2020년 2월 12일
Hi community, i am doing a task, of extracting color features and gobar features, after extracting these features, i am trying to cancate them but it gives error message
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in practice_code (line 19)
Fused_Features = [Extracted_Color_Features, Extracted_Gabor_Features];
i am trying to use vertcat and horzcat function for cancatenating these two features the reason of using these two function is because color features obtained in horizontal position, and gobar features are obtained in vertical features. but still same error are shown. the dimension of color features are 4478x1 and gobar features are 24000x1
so what can i do?

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 12일
Fused_Features = [Extracted_Color_Features; Extracted_Gabor_Features];
  댓글 수: 2
Awais Khan
Awais Khan 2020년 2월 12일
can you explain what is the purpose of ; because i am using same code but instead of ; i am using , as a result it given an error.
Walter Roberson
Walter Roberson 2020년 2월 12일
vertcat is equivalent to using square brackets for vertically concatenating arrays. For example, [A; B] is equal to vertcat(A,B) when A and B are compatible arrays.
horzcat is equivalent to using square brackets for horizontally concatenating arrays. For example, [A,B] or [A B] is equal to horzcat(A,B) when A and B are compatible arrays.
Phrasing that another way:
  • When you write [A, B] or [A B], what really gets called is horzcat(A,B) -- writing [] is "syntactic sugar", something to make programming easier but which is internally translated to something else.
  • When you write [A;B], what really gets called is vertcat(A,B) -- more syntactic sugar
Also, when you code
[A
B]
what really gets called is vertcat(A,B). And
[A B
C D]
would internally be translated to
vertcat(horzcat(A, B), horzcat(C, D))
If you happened to have
[A B
C]
then you should suspect that there is an error, but it is not necessarily an error. The important part is not the number of expressions: it is whether the expressions expand to compatible sizes. It is, for example, completely valid to have
[1 2 3 4
zeros(1,4)]
which internally would be
vertcat( horzcat(1,2,3,4), zeros(1,4) )

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by