Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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?

Antworten (2)

Stephen23
Stephen23 am 4 Aug. 2016
Bearbeitet: Stephen23 am 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 Kommentare
shefna manaf
shefna manaf am 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 am 5 Aug. 2016
Bearbeitet: Stephen23 am 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 ?

Melden Sie sich an, um zu kommentieren.


Guillaume
Guillaume am 5 Aug. 2016
Bearbeitet: Guillaume am 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!

Translated by