Dimensions of arrays being concatenated are not consistent

3 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 12 Feb 2020
Fused_Features = [Extracted_Color_Features; Extracted_Gabor_Features];
  2 Comments
Awais Khan
Awais Khan on 12 Feb 2020
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 on 12 Feb 2020
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) )

Sign in to comment.

More Answers (0)

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!