Clear Filters
Clear Filters

how to solve this error 'Error using horzcat Dimensions of matrices being concatenated are not consistent.'

2 views (last 30 days)
this is the error i get when i run my code.
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in MutualInfo (line 7) jointHistogram = accumarray([indrow indcol], 1);
Error in Nmutualinfol (line 103) [value,ind]=max(MutualInfo(b,a'));
size(a) 1 16384
size(b) 16384 181
can anyone please help me?

Answers (2)

Stephen23
Stephen23 on 4 Aug 2016
Edited: Stephen23 on 5 Aug 2016
Taking a wild guess:
[value,ind] = max(MutualInfo(b.',a.'));
or
[value,ind] = max(MutualInfo(b,a));
But really we need to see your code.
  2 Comments
shefna manaf
shefna manaf on 5 Aug 2016
thank you Stephen Cobeldick..but it doesnt work...still getting the same error. I have attached my work files...can you please have a look?
Stephen23
Stephen23 on 5 Aug 2016
Edited: Stephen23 on 5 Aug 2016
There is a bug in your original code: you try to concatenate the indices [indrow indcol], but these actually have totally different sizes.
You need to learn how to debug code: looking at a and b is a great start, but do you know what sizes those indices are? You define them as:
[~,~,indrow] = unique(im1(:))
[~,~,indcol] = unique(im2(:))
but because you used the (:) operation then im1 and im2 are rearranged into column vectors. indrow has 16384 elements (rows, because it is a column vector), and indcol has 2965504 elements (rows). Are the numbers of rows the same ? No. Can these be concatenated together horizontally ? No, because they have a different number of rows.
Solution: Ask the person who wrote the code to explain to you what it should do, understand the algorithm, and fix it. You appeared to have attempted this, because the code you uploaded in your comment is different to the one in your question:
accumarray([indrow indcol], 1); % question
accumarray([indrow.' indcol.'], 1); % uploaded
So, did this fix the problem ?

Sign in to comment.


Guillaume
Guillaume on 5 Aug 2016
Edited: Guillaume on 5 Aug 2016
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in MutualInfo (line 7) jointHistogram = accumarray([indrow indcol], 1);
Well then, the only way to get the error in the above line is if indrow and indcol are not the same size.
Looking at the code of MutualInfo, indrow is a column vector of length numel(Im1), indcol is a column vector of length numel(im2). Therefore, your a (im1) and b (im2) must have the same numbers of pixels.
That is clearly not the case. Considering that a is a single column of an image whereas b is a whole image they'll never be the same size and you can't pass them to MutualInfo.
I don't know what you're trying to do, but you need to rethink your algorithm.
Note: there is no point of transposing a and b in the code to MutualInfo, the shape of the inputs do not matter, since MutualInfo reshape them in column vectors anyway.

Community Treasure Hunt

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

Start Hunting!